1ff12d537SAndre Fischer /************************************************************** 2ff12d537SAndre Fischer * 3ff12d537SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4ff12d537SAndre Fischer * or more contributor license agreements. See the NOTICE file 5ff12d537SAndre Fischer * distributed with this work for additional information 6ff12d537SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7ff12d537SAndre Fischer * to you under the Apache License, Version 2.0 (the 8ff12d537SAndre Fischer * "License"); you may not use this file except in compliance 9ff12d537SAndre Fischer * with the License. You may obtain a copy of the License at 10ff12d537SAndre Fischer * 11ff12d537SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12ff12d537SAndre Fischer * 13ff12d537SAndre Fischer * Unless required by applicable law or agreed to in writing, 14ff12d537SAndre Fischer * software distributed under the License is distributed on an 15ff12d537SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ff12d537SAndre Fischer * KIND, either express or implied. See the License for the 17ff12d537SAndre Fischer * specific language governing permissions and limitations 18ff12d537SAndre Fischer * under the License. 19ff12d537SAndre Fischer * 20ff12d537SAndre Fischer *************************************************************/ 21ff12d537SAndre Fischer 22ff12d537SAndre Fischer #include "precompiled_sfx2.hxx" 23ff12d537SAndre Fischer 24ff12d537SAndre Fischer #include "ResourceManager.hxx" 25ff12d537SAndre Fischer #include <unotools/confignode.hxx> 26ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx> 2795a18594SAndre Fischer #include <comphelper/processfactory.hxx> 28ff12d537SAndre Fischer #include <comphelper/namedvaluecollection.hxx> 2995a18594SAndre Fischer #include <comphelper/types.hxx> 30*7a32b0c8SAndre Fischer #include <comphelper/stlunosequence.hxx> 31*7a32b0c8SAndre Fischer 3295a18594SAndre Fischer #include <rtl/ustrbuf.hxx> 33ff12d537SAndre Fischer #include <tools/diagnose_ex.h> 34ff12d537SAndre Fischer 3595a18594SAndre Fischer #include <com/sun/star/frame/XModuleManager.hpp> 3695a18594SAndre Fischer 3795a18594SAndre Fischer #include <map> 3895a18594SAndre Fischer 39ff12d537SAndre Fischer 40ff12d537SAndre Fischer #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 41ff12d537SAndre Fischer 42ff12d537SAndre Fischer using ::rtl::OUString; 43ff12d537SAndre Fischer using namespace css; 44ff12d537SAndre Fischer using namespace cssu; 45ff12d537SAndre Fischer 46ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 47ff12d537SAndre Fischer 48ff12d537SAndre Fischer #define gsPrivateResourceToolpanelPrefix "private:resource/toolpanel/" 49ff12d537SAndre Fischer 50ff12d537SAndre Fischer 51ff12d537SAndre Fischer 52ff12d537SAndre Fischer class ResourceManager::Deleter 53ff12d537SAndre Fischer { 54ff12d537SAndre Fischer public: 55ff12d537SAndre Fischer void operator() (ResourceManager* pObject) 56ff12d537SAndre Fischer { 57ff12d537SAndre Fischer delete pObject; 58ff12d537SAndre Fischer } 59ff12d537SAndre Fischer }; 60ff12d537SAndre Fischer 61ff12d537SAndre Fischer 62ff12d537SAndre Fischer ResourceManager& ResourceManager::Instance (void) 63ff12d537SAndre Fischer { 64ff12d537SAndre Fischer static ResourceManager maInstance; 65ff12d537SAndre Fischer return maInstance; 66ff12d537SAndre Fischer } 67ff12d537SAndre Fischer 68ff12d537SAndre Fischer 69ff12d537SAndre Fischer 70ff12d537SAndre Fischer 71ff12d537SAndre Fischer ResourceManager::ResourceManager (void) 72ff12d537SAndre Fischer : maDecks(), 73ff12d537SAndre Fischer maPanels(), 74ff12d537SAndre Fischer maProcessedApplications() 75ff12d537SAndre Fischer { 76ff12d537SAndre Fischer ReadDeckList(); 77ff12d537SAndre Fischer ReadPanelList(); 78ff12d537SAndre Fischer } 79ff12d537SAndre Fischer 80ff12d537SAndre Fischer 81ff12d537SAndre Fischer 82ff12d537SAndre Fischer 83ff12d537SAndre Fischer ResourceManager::~ResourceManager (void) 84ff12d537SAndre Fischer { 85ff12d537SAndre Fischer maPanels.clear(); 86ff12d537SAndre Fischer maDecks.clear(); 87ff12d537SAndre Fischer } 88ff12d537SAndre Fischer 89ff12d537SAndre Fischer 90ff12d537SAndre Fischer 91ff12d537SAndre Fischer 92ff12d537SAndre Fischer const DeckDescriptor* ResourceManager::GetBestMatchingDeck ( 93*7a32b0c8SAndre Fischer const Context& rContext, 94ff12d537SAndre Fischer const Reference<frame::XFrame>& rxFrame) 95ff12d537SAndre Fischer { 96ff12d537SAndre Fischer ReadLegacyAddons(rxFrame); 97ff12d537SAndre Fischer 9895a18594SAndre Fischer sal_Int32 nBestMatch (EnumContext::NoMatch); 99ff12d537SAndre Fischer const DeckContainer::const_iterator iEnd (maDecks.end()); 100ff12d537SAndre Fischer DeckContainer::const_iterator iBestDeck (iEnd); 101ff12d537SAndre Fischer 102ff12d537SAndre Fischer for (DeckContainer::const_iterator iDeck(maDecks.begin()); 103ff12d537SAndre Fischer iDeck!=iEnd; 104ff12d537SAndre Fischer ++iDeck) 105ff12d537SAndre Fischer { 106*7a32b0c8SAndre Fischer const sal_Int32 nMatch (iDeck->maContextMatcher.EvaluateMatch(rContext)); 107ff12d537SAndre Fischer if (nMatch < nBestMatch) 108ff12d537SAndre Fischer { 10995a18594SAndre Fischer // Found a better matching deck. 110ff12d537SAndre Fischer nBestMatch = nMatch; 111ff12d537SAndre Fischer iBestDeck = iDeck; 11295a18594SAndre Fischer if (nBestMatch == EnumContext::OptimalMatch) 113ff12d537SAndre Fischer { 114ff12d537SAndre Fischer // We will not find a better match. 115ff12d537SAndre Fischer break; 116ff12d537SAndre Fischer } 117ff12d537SAndre Fischer } 118ff12d537SAndre Fischer } 119ff12d537SAndre Fischer if (iBestDeck != iEnd) 120ff12d537SAndre Fischer return &*iBestDeck; 121ff12d537SAndre Fischer else 122ff12d537SAndre Fischer return NULL; 123ff12d537SAndre Fischer } 124ff12d537SAndre Fischer 125ff12d537SAndre Fischer 126ff12d537SAndre Fischer 127ff12d537SAndre Fischer 12895a18594SAndre Fischer const DeckDescriptor* ResourceManager::GetDeckDescriptor ( 12995a18594SAndre Fischer const ::rtl::OUString& rsDeckId) const 13095a18594SAndre Fischer { 13195a18594SAndre Fischer for (DeckContainer::const_iterator 13295a18594SAndre Fischer iDeck(maDecks.begin()), 13395a18594SAndre Fischer iEnd(maDecks.end()); 13495a18594SAndre Fischer iDeck!=iEnd; 13595a18594SAndre Fischer ++iDeck) 13695a18594SAndre Fischer { 13795a18594SAndre Fischer if (iDeck->msId.equals(rsDeckId)) 13895a18594SAndre Fischer return &*iDeck; 13995a18594SAndre Fischer } 14095a18594SAndre Fischer return NULL; 14195a18594SAndre Fischer } 14295a18594SAndre Fischer 14395a18594SAndre Fischer 14495a18594SAndre Fischer 14595a18594SAndre Fischer 14695a18594SAndre Fischer const PanelDescriptor* ResourceManager::GetPanelDescriptor ( 14795a18594SAndre Fischer const ::rtl::OUString& rsPanelId) const 14895a18594SAndre Fischer { 14995a18594SAndre Fischer for (PanelContainer::const_iterator 15095a18594SAndre Fischer iPanel(maPanels.begin()), 15195a18594SAndre Fischer iEnd(maPanels.end()); 15295a18594SAndre Fischer iPanel!=iEnd; 15395a18594SAndre Fischer ++iPanel) 15495a18594SAndre Fischer { 15595a18594SAndre Fischer if (iPanel->msId.equals(rsPanelId)) 15695a18594SAndre Fischer return &*iPanel; 15795a18594SAndre Fischer } 15895a18594SAndre Fischer return NULL; 15995a18594SAndre Fischer } 16095a18594SAndre Fischer 16195a18594SAndre Fischer 16295a18594SAndre Fischer 16395a18594SAndre Fischer 16495a18594SAndre Fischer void ResourceManager::SetIsDeckEnabled ( 16595a18594SAndre Fischer const ::rtl::OUString& rsDeckId, 16695a18594SAndre Fischer const bool bIsEnabled) 16795a18594SAndre Fischer { 16895a18594SAndre Fischer for (DeckContainer::iterator 16995a18594SAndre Fischer iDeck(maDecks.begin()), 17095a18594SAndre Fischer iEnd(maDecks.end()); 17195a18594SAndre Fischer iDeck!=iEnd; 17295a18594SAndre Fischer ++iDeck) 17395a18594SAndre Fischer { 17495a18594SAndre Fischer if (iDeck->msId.equals(rsDeckId)) 17595a18594SAndre Fischer { 17695a18594SAndre Fischer iDeck->mbIsEnabled = bIsEnabled; 17795a18594SAndre Fischer return; 17895a18594SAndre Fischer } 17995a18594SAndre Fischer } 18095a18594SAndre Fischer } 18195a18594SAndre Fischer 18295a18594SAndre Fischer 18395a18594SAndre Fischer 18495a18594SAndre Fischer 18595a18594SAndre Fischer const ResourceManager::IdContainer& ResourceManager::GetMatchingDecks ( 18695a18594SAndre Fischer IdContainer& rDeckIds, 187*7a32b0c8SAndre Fischer const Context& rContext, 188ff12d537SAndre Fischer const Reference<frame::XFrame>& rxFrame) 189ff12d537SAndre Fischer { 190ff12d537SAndre Fischer ReadLegacyAddons(rxFrame); 191ff12d537SAndre Fischer 192*7a32b0c8SAndre Fischer ::std::multimap<sal_Int32,OUString> aOrderedIds; 193ff12d537SAndre Fischer for (DeckContainer::const_iterator 194ff12d537SAndre Fischer iDeck(maDecks.begin()), 195ff12d537SAndre Fischer iEnd (maDecks.end()); 196ff12d537SAndre Fischer iDeck!=iEnd; 197ff12d537SAndre Fischer ++iDeck) 198ff12d537SAndre Fischer { 199*7a32b0c8SAndre Fischer const DeckDescriptor& rDeckDescriptor (*iDeck); 200*7a32b0c8SAndre Fischer if (rDeckDescriptor.maContextMatcher.EvaluateMatch(rContext) != EnumContext::NoMatch) 201*7a32b0c8SAndre Fischer aOrderedIds.insert(::std::multimap<sal_Int32,OUString>::value_type( 202*7a32b0c8SAndre Fischer rDeckDescriptor.mnOrderIndex, 203*7a32b0c8SAndre Fischer rDeckDescriptor.msId)); 204*7a32b0c8SAndre Fischer } 205*7a32b0c8SAndre Fischer 206*7a32b0c8SAndre Fischer for (::std::multimap<sal_Int32,OUString>::const_iterator 207*7a32b0c8SAndre Fischer iId(aOrderedIds.begin()), 208*7a32b0c8SAndre Fischer iEnd(aOrderedIds.end()); 209*7a32b0c8SAndre Fischer iId!=iEnd; 210*7a32b0c8SAndre Fischer ++iId) 211*7a32b0c8SAndre Fischer { 212*7a32b0c8SAndre Fischer rDeckIds.push_back(iId->second); 213ff12d537SAndre Fischer } 214ff12d537SAndre Fischer 21595a18594SAndre Fischer return rDeckIds; 216ff12d537SAndre Fischer } 217ff12d537SAndre Fischer 218ff12d537SAndre Fischer 219ff12d537SAndre Fischer 220ff12d537SAndre Fischer 22195a18594SAndre Fischer const ResourceManager::IdContainer& ResourceManager::GetMatchingPanels ( 22295a18594SAndre Fischer IdContainer& rPanelIds, 223*7a32b0c8SAndre Fischer const Context& rContext, 224ff12d537SAndre Fischer const ::rtl::OUString& rsDeckId, 225ff12d537SAndre Fischer const Reference<frame::XFrame>& rxFrame) 226ff12d537SAndre Fischer { 227ff12d537SAndre Fischer ReadLegacyAddons(rxFrame); 228ff12d537SAndre Fischer 22995a18594SAndre Fischer ::std::multimap<sal_Int32,OUString> aOrderedIds; 230ff12d537SAndre Fischer for (PanelContainer::const_iterator 231ff12d537SAndre Fischer iPanel(maPanels.begin()), 232ff12d537SAndre Fischer iEnd(maPanels.end()); 233ff12d537SAndre Fischer iPanel!=iEnd; 234ff12d537SAndre Fischer ++iPanel) 235ff12d537SAndre Fischer { 236ff12d537SAndre Fischer const PanelDescriptor& rPanelDescriptor (*iPanel); 237ff12d537SAndre Fischer if (rPanelDescriptor.msDeckId.equals(rsDeckId)) 238*7a32b0c8SAndre Fischer if (rPanelDescriptor.maContextMatcher.EvaluateMatch(rContext) != EnumContext::NoMatch) 23995a18594SAndre Fischer aOrderedIds.insert(::std::multimap<sal_Int32,OUString>::value_type( 240*7a32b0c8SAndre Fischer rPanelDescriptor.mnOrderIndex, 241*7a32b0c8SAndre Fischer rPanelDescriptor.msId)); 242ff12d537SAndre Fischer } 243ff12d537SAndre Fischer 24495a18594SAndre Fischer for (::std::multimap<sal_Int32,OUString>::const_iterator 24595a18594SAndre Fischer iId(aOrderedIds.begin()), 24695a18594SAndre Fischer iEnd(aOrderedIds.end()); 24795a18594SAndre Fischer iId!=iEnd; 24895a18594SAndre Fischer ++iId) 24995a18594SAndre Fischer { 25095a18594SAndre Fischer rPanelIds.push_back(iId->second); 25195a18594SAndre Fischer } 25295a18594SAndre Fischer 25395a18594SAndre Fischer return rPanelIds; 254ff12d537SAndre Fischer } 255ff12d537SAndre Fischer 256ff12d537SAndre Fischer 257ff12d537SAndre Fischer 258ff12d537SAndre Fischer 259ff12d537SAndre Fischer void ResourceManager::ReadDeckList (void) 260ff12d537SAndre Fischer { 261ff12d537SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 262ff12d537SAndre Fischer const ::utl::OConfigurationTreeRoot aDeckRootNode ( 263ff12d537SAndre Fischer aContext, 264ff12d537SAndre Fischer A2S("org.openoffice.Office.UI.Sidebar/Content/DeckList"), 265ff12d537SAndre Fischer false); 266ff12d537SAndre Fischer if ( ! aDeckRootNode.isValid() ) 267ff12d537SAndre Fischer return; 268ff12d537SAndre Fischer 269ff12d537SAndre Fischer const Sequence<OUString> aDeckNodeNames (aDeckRootNode.getNodeNames()); 270ff12d537SAndre Fischer const sal_Int32 nCount (aDeckNodeNames.getLength()); 271ff12d537SAndre Fischer maDecks.resize(nCount); 272ff12d537SAndre Fischer sal_Int32 nWriteIndex(0); 273ff12d537SAndre Fischer for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex) 274ff12d537SAndre Fischer { 275ff12d537SAndre Fischer const ::utl::OConfigurationNode aDeckNode (aDeckRootNode.openNode(aDeckNodeNames[nReadIndex])); 276ff12d537SAndre Fischer if ( ! aDeckNode.isValid()) 277ff12d537SAndre Fischer continue; 278ff12d537SAndre Fischer 279ff12d537SAndre Fischer DeckDescriptor& rDeckDescriptor (maDecks[nWriteIndex++]); 280ff12d537SAndre Fischer 281*7a32b0c8SAndre Fischer rDeckDescriptor.msTitle = ::comphelper::getString( 282*7a32b0c8SAndre Fischer aDeckNode.getNodeValue("Title")); 283*7a32b0c8SAndre Fischer rDeckDescriptor.msId = ::comphelper::getString( 284*7a32b0c8SAndre Fischer aDeckNode.getNodeValue("Id")); 285*7a32b0c8SAndre Fischer rDeckDescriptor.msIconURL = ::comphelper::getString( 286*7a32b0c8SAndre Fischer aDeckNode.getNodeValue("IconURL")); 287*7a32b0c8SAndre Fischer rDeckDescriptor.msHighContrastIconURL = ::comphelper::getString( 288*7a32b0c8SAndre Fischer aDeckNode.getNodeValue("HighContrastIconURL")); 289*7a32b0c8SAndre Fischer rDeckDescriptor.msHelpURL = ::comphelper::getString( 290*7a32b0c8SAndre Fischer aDeckNode.getNodeValue("HelpURL")); 291ff12d537SAndre Fischer rDeckDescriptor.msHelpText = rDeckDescriptor.msTitle; 29295a18594SAndre Fischer rDeckDescriptor.mbIsEnabled = true; 293*7a32b0c8SAndre Fischer rDeckDescriptor.mnOrderIndex = ::comphelper::getINT32( 294*7a32b0c8SAndre Fischer aDeckNode.getNodeValue("OrderIndex")); 295*7a32b0c8SAndre Fischer 296*7a32b0c8SAndre Fischer ReadContextMatcher(aDeckNode.openNode("ContextMatchers"), rDeckDescriptor.maContextMatcher); 297ff12d537SAndre Fischer } 298ff12d537SAndre Fischer 299ff12d537SAndre Fischer // When there where invalid nodes then we have to adapt the size 300ff12d537SAndre Fischer // of the deck vector. 301ff12d537SAndre Fischer if (nWriteIndex<nCount) 302ff12d537SAndre Fischer maDecks.resize(nWriteIndex); 303ff12d537SAndre Fischer } 304ff12d537SAndre Fischer 305ff12d537SAndre Fischer 306ff12d537SAndre Fischer 307ff12d537SAndre Fischer 308ff12d537SAndre Fischer void ResourceManager::ReadPanelList (void) 309ff12d537SAndre Fischer { 310ff12d537SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 311ff12d537SAndre Fischer const ::utl::OConfigurationTreeRoot aPanelRootNode ( 312ff12d537SAndre Fischer aContext, 313ff12d537SAndre Fischer A2S("org.openoffice.Office.UI.Sidebar/Content/PanelList"), 314ff12d537SAndre Fischer false); 315ff12d537SAndre Fischer if ( ! aPanelRootNode.isValid() ) 316ff12d537SAndre Fischer return; 317ff12d537SAndre Fischer 318ff12d537SAndre Fischer const Sequence<OUString> aPanelNodeNames (aPanelRootNode.getNodeNames()); 319ff12d537SAndre Fischer const sal_Int32 nCount (aPanelNodeNames.getLength()); 320ff12d537SAndre Fischer maPanels.resize(nCount); 321ff12d537SAndre Fischer sal_Int32 nWriteIndex (0); 322ff12d537SAndre Fischer for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex) 323ff12d537SAndre Fischer { 324ff12d537SAndre Fischer const ::utl::OConfigurationNode aPanelNode (aPanelRootNode.openNode(aPanelNodeNames[nReadIndex])); 325ff12d537SAndre Fischer if ( ! aPanelNode.isValid()) 326ff12d537SAndre Fischer continue; 327ff12d537SAndre Fischer 328ff12d537SAndre Fischer PanelDescriptor& rPanelDescriptor (maPanels[nWriteIndex++]); 329ff12d537SAndre Fischer 330ff12d537SAndre Fischer rPanelDescriptor.msTitle = ::comphelper::getString( 331ff12d537SAndre Fischer aPanelNode.getNodeValue("Title")); 332ff12d537SAndre Fischer rPanelDescriptor.mbIsTitleBarOptional = ::comphelper::getBOOL( 333ff12d537SAndre Fischer aPanelNode.getNodeValue("TitleBarIsOptional")); 334ff12d537SAndre Fischer rPanelDescriptor.msId = ::comphelper::getString( 335ff12d537SAndre Fischer aPanelNode.getNodeValue("Id")); 336ff12d537SAndre Fischer rPanelDescriptor.msDeckId = ::comphelper::getString( 337ff12d537SAndre Fischer aPanelNode.getNodeValue("DeckId")); 338ff12d537SAndre Fischer rPanelDescriptor.msHelpURL = ::comphelper::getString( 339ff12d537SAndre Fischer aPanelNode.getNodeValue("HelpURL")); 340ff12d537SAndre Fischer rPanelDescriptor.msImplementationURL = ::comphelper::getString( 341ff12d537SAndre Fischer aPanelNode.getNodeValue("ImplementationURL")); 34295a18594SAndre Fischer rPanelDescriptor.mnOrderIndex = ::comphelper::getINT32( 34395a18594SAndre Fischer aPanelNode.getNodeValue("OrderIndex")); 344*7a32b0c8SAndre Fischer rPanelDescriptor.mbHasMenu = ::comphelper::getBOOL( 345*7a32b0c8SAndre Fischer aPanelNode.getNodeValue("HasMenu")); 346*7a32b0c8SAndre Fischer rPanelDescriptor.mbWantsCanvas = ::comphelper::getBOOL( 347*7a32b0c8SAndre Fischer aPanelNode.getNodeValue("WantsCanvas")); 348*7a32b0c8SAndre Fischer ReadContextMatcher(aPanelNode.openNode("ContextMatchers"), rPanelDescriptor.maContextMatcher); 349ff12d537SAndre Fischer } 350ff12d537SAndre Fischer 351ff12d537SAndre Fischer // When there where invalid nodes then we have to adapt the size 352ff12d537SAndre Fischer // of the deck vector. 353ff12d537SAndre Fischer if (nWriteIndex<nCount) 354ff12d537SAndre Fischer maPanels.resize(nWriteIndex); 355ff12d537SAndre Fischer } 356ff12d537SAndre Fischer 357ff12d537SAndre Fischer 358ff12d537SAndre Fischer 359ff12d537SAndre Fischer 360*7a32b0c8SAndre Fischer void ResourceManager::ReadContextMatcher ( 361ff12d537SAndre Fischer const ::utl::OConfigurationNode& rNode, 362*7a32b0c8SAndre Fischer ContextMatcher& rContextMatcher) const 363ff12d537SAndre Fischer { 364*7a32b0c8SAndre Fischer const Sequence<OUString> aMatcherNodeNames (rNode.getNodeNames()); 365*7a32b0c8SAndre Fischer const sal_Int32 nMatcherCount (aMatcherNodeNames.getLength()); 366*7a32b0c8SAndre Fischer for (sal_Int32 nMatcherIndex(0); nMatcherIndex<nMatcherCount; ++nMatcherIndex) 367ff12d537SAndre Fischer { 368*7a32b0c8SAndre Fischer const ::utl::OConfigurationNode aMatcherNode (rNode.openNode(aMatcherNodeNames[nMatcherIndex])); 369*7a32b0c8SAndre Fischer 370*7a32b0c8SAndre Fischer const OUString sApplicationName ( 371*7a32b0c8SAndre Fischer ::comphelper::getString(aMatcherNode.getNodeValue("Application"))); 372*7a32b0c8SAndre Fischer const bool bIsContextListNegated ( 373*7a32b0c8SAndre Fischer ::comphelper::getBOOL(aMatcherNode.getNodeValue("IsContextListNegated"))); 374*7a32b0c8SAndre Fischer 375*7a32b0c8SAndre Fischer // Read the context names. 376*7a32b0c8SAndre Fischer Any aContextListValue (aMatcherNode.getNodeValue("ContextList")); 377*7a32b0c8SAndre Fischer Sequence<OUString> aContextList; 378*7a32b0c8SAndre Fischer ::std::vector<OUString> aContextVector; 379*7a32b0c8SAndre Fischer if (aContextListValue >>= aContextList) 380*7a32b0c8SAndre Fischer { 381*7a32b0c8SAndre Fischer aContextVector.reserve(aContextList.getLength()); 382*7a32b0c8SAndre Fischer ::std::copy( 383*7a32b0c8SAndre Fischer ::comphelper::stl_begin(aContextList), 384*7a32b0c8SAndre Fischer ::comphelper::stl_end(aContextList), 385*7a32b0c8SAndre Fischer ::std::back_inserter(aContextVector)); 386*7a32b0c8SAndre Fischer } 387*7a32b0c8SAndre Fischer // Empty list defaults to "any". 388*7a32b0c8SAndre Fischer if (aContextVector.empty()) 389*7a32b0c8SAndre Fischer aContextVector.push_back(A2S("any")); 390*7a32b0c8SAndre Fischer 391*7a32b0c8SAndre Fischer rContextMatcher.AddMatcher( 392*7a32b0c8SAndre Fischer sApplicationName, 393*7a32b0c8SAndre Fischer aContextVector, 394*7a32b0c8SAndre Fischer bIsContextListNegated); 395ff12d537SAndre Fischer } 396ff12d537SAndre Fischer } 397ff12d537SAndre Fischer 398ff12d537SAndre Fischer 399ff12d537SAndre Fischer 400ff12d537SAndre Fischer 401ff12d537SAndre Fischer void ResourceManager::ReadLegacyAddons (const Reference<frame::XFrame>& rxFrame) 402ff12d537SAndre Fischer { 403ff12d537SAndre Fischer // Get module name for given frame. 404ff12d537SAndre Fischer ::rtl::OUString sModuleName (GetModuleName(rxFrame)); 405ff12d537SAndre Fischer if (sModuleName.getLength() == 0) 406ff12d537SAndre Fischer return; 407ff12d537SAndre Fischer if (maProcessedApplications.find(sModuleName) != maProcessedApplications.end()) 408ff12d537SAndre Fischer { 409ff12d537SAndre Fischer // Addons for this application have already been read. 410ff12d537SAndre Fischer // There is nothing more to do. 411ff12d537SAndre Fischer return; 412ff12d537SAndre Fischer } 413ff12d537SAndre Fischer 414ff12d537SAndre Fischer // Mark module as processed. Even when there is an error that 415ff12d537SAndre Fischer // prevents the configuration data from being read, this error 416ff12d537SAndre Fischer // will not be triggered a second time. 417ff12d537SAndre Fischer maProcessedApplications.insert(sModuleName); 418ff12d537SAndre Fischer 419ff12d537SAndre Fischer // Get access to the configuration root node for the application. 420ff12d537SAndre Fischer ::utl::OConfigurationTreeRoot aLegacyRootNode (GetLegacyAddonRootNode(sModuleName)); 421ff12d537SAndre Fischer if ( ! aLegacyRootNode.isValid()) 422ff12d537SAndre Fischer return; 423ff12d537SAndre Fischer 424ff12d537SAndre Fischer // Process child nodes. 425ff12d537SAndre Fischer ::std::vector<OUString> aMatchingNodeNames; 426ff12d537SAndre Fischer GetToolPanelNodeNames(aMatchingNodeNames, aLegacyRootNode); 427ff12d537SAndre Fischer const sal_Int32 nCount (aMatchingNodeNames.size()); 42895a18594SAndre Fischer size_t nDeckWriteIndex (maDecks.size()); 42995a18594SAndre Fischer size_t nPanelWriteIndex (maPanels.size()); 430ff12d537SAndre Fischer maDecks.resize(maDecks.size() + nCount); 431ff12d537SAndre Fischer maPanels.resize(maPanels.size() + nCount); 432ff12d537SAndre Fischer for (sal_Int32 nReadIndex(0); nReadIndex<nCount; ++nReadIndex) 433ff12d537SAndre Fischer { 434ff12d537SAndre Fischer const OUString& rsNodeName (aMatchingNodeNames[nReadIndex]); 435ff12d537SAndre Fischer const ::utl::OConfigurationNode aChildNode (aLegacyRootNode.openNode(rsNodeName)); 436ff12d537SAndre Fischer if ( ! aChildNode.isValid()) 437ff12d537SAndre Fischer continue; 438ff12d537SAndre Fischer 439ff12d537SAndre Fischer DeckDescriptor& rDeckDescriptor (maDecks[nDeckWriteIndex++]); 440ff12d537SAndre Fischer rDeckDescriptor.msTitle = ::comphelper::getString(aChildNode.getNodeValue("UIName")); 441ff12d537SAndre Fischer rDeckDescriptor.msId = rsNodeName; 442ff12d537SAndre Fischer rDeckDescriptor.msIconURL = ::comphelper::getString(aChildNode.getNodeValue("ImageURL")); 443ff12d537SAndre Fischer rDeckDescriptor.msHighContrastIconURL = rDeckDescriptor.msIconURL; 444ff12d537SAndre Fischer rDeckDescriptor.msHelpURL = ::comphelper::getString(aChildNode.getNodeValue("HelpURL")); 445ff12d537SAndre Fischer rDeckDescriptor.msHelpText = rDeckDescriptor.msTitle; 446*7a32b0c8SAndre Fischer rDeckDescriptor.maContextMatcher.AddMatcher(sModuleName, A2S("any")); 44795a18594SAndre Fischer rDeckDescriptor.mbIsEnabled = true; 448ff12d537SAndre Fischer 449ff12d537SAndre Fischer PanelDescriptor& rPanelDescriptor (maPanels[nPanelWriteIndex++]); 450ff12d537SAndre Fischer rPanelDescriptor.msTitle = ::comphelper::getString(aChildNode.getNodeValue("UIName")); 451*7a32b0c8SAndre Fischer rPanelDescriptor.mbIsTitleBarOptional = true; 452ff12d537SAndre Fischer rPanelDescriptor.msId = rsNodeName; 453ff12d537SAndre Fischer rPanelDescriptor.msDeckId = rsNodeName; 454ff12d537SAndre Fischer rPanelDescriptor.msHelpURL = ::comphelper::getString(aChildNode.getNodeValue("HelpURL")); 455*7a32b0c8SAndre Fischer rPanelDescriptor.maContextMatcher.AddMatcher(sModuleName, A2S("any")); 456ff12d537SAndre Fischer rPanelDescriptor.msImplementationURL = rsNodeName; 457ff12d537SAndre Fischer } 458ff12d537SAndre Fischer 459ff12d537SAndre Fischer // When there where invalid nodes then we have to adapt the size 460ff12d537SAndre Fischer // of the deck and panel vectors. 461ff12d537SAndre Fischer if (nDeckWriteIndex < maDecks.size()) 462ff12d537SAndre Fischer maDecks.resize(nDeckWriteIndex); 463ff12d537SAndre Fischer if (nPanelWriteIndex < maPanels.size()) 464ff12d537SAndre Fischer maPanels.resize(nPanelWriteIndex); 465ff12d537SAndre Fischer } 466ff12d537SAndre Fischer 467ff12d537SAndre Fischer 468ff12d537SAndre Fischer 469ff12d537SAndre Fischer 470ff12d537SAndre Fischer ::rtl::OUString ResourceManager::GetModuleName ( 47195a18594SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 472ff12d537SAndre Fischer { 473ff12d537SAndre Fischer try 474ff12d537SAndre Fischer { 475ff12d537SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 476ff12d537SAndre Fischer const Reference<frame::XModuleManager> xModuleManager ( 477ff12d537SAndre Fischer aContext.createComponent("com.sun.star.frame.ModuleManager" ), 478ff12d537SAndre Fischer UNO_QUERY_THROW ); 479ff12d537SAndre Fischer return xModuleManager->identify(rxFrame); 480ff12d537SAndre Fischer } 481ff12d537SAndre Fischer catch (const Exception&) 482ff12d537SAndre Fischer { 483ff12d537SAndre Fischer DBG_UNHANDLED_EXCEPTION(); 484ff12d537SAndre Fischer } 485ff12d537SAndre Fischer return OUString(); 486ff12d537SAndre Fischer } 487ff12d537SAndre Fischer 488ff12d537SAndre Fischer 489ff12d537SAndre Fischer 490ff12d537SAndre Fischer 491ff12d537SAndre Fischer ::utl::OConfigurationTreeRoot ResourceManager::GetLegacyAddonRootNode ( 492ff12d537SAndre Fischer const ::rtl::OUString& rsModuleName) const 493ff12d537SAndre Fischer { 494ff12d537SAndre Fischer try 495ff12d537SAndre Fischer { 496ff12d537SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 497ff12d537SAndre Fischer const Reference<container::XNameAccess> xModuleAccess ( 498ff12d537SAndre Fischer aContext.createComponent("com.sun.star.frame.ModuleManager"), 499ff12d537SAndre Fischer UNO_QUERY_THROW); 500ff12d537SAndre Fischer const ::comphelper::NamedValueCollection aModuleProperties (xModuleAccess->getByName(rsModuleName)); 501ff12d537SAndre Fischer const ::rtl::OUString sWindowStateRef (aModuleProperties.getOrDefault( 502ff12d537SAndre Fischer "ooSetupFactoryWindowStateConfigRef", 503ff12d537SAndre Fischer ::rtl::OUString())); 504ff12d537SAndre Fischer 505ff12d537SAndre Fischer ::rtl::OUStringBuffer aPathComposer; 506ff12d537SAndre Fischer aPathComposer.appendAscii("org.openoffice.Office.UI."); 507ff12d537SAndre Fischer aPathComposer.append(sWindowStateRef); 508ff12d537SAndre Fischer aPathComposer.appendAscii("/UIElements/States"); 509ff12d537SAndre Fischer 510ff12d537SAndre Fischer return ::utl::OConfigurationTreeRoot(aContext, aPathComposer.makeStringAndClear(), false); 511ff12d537SAndre Fischer } 512ff12d537SAndre Fischer catch( const Exception& ) 513ff12d537SAndre Fischer { 514ff12d537SAndre Fischer DBG_UNHANDLED_EXCEPTION(); 515ff12d537SAndre Fischer } 516ff12d537SAndre Fischer 517ff12d537SAndre Fischer return ::utl::OConfigurationTreeRoot(); 518ff12d537SAndre Fischer } 519ff12d537SAndre Fischer 520ff12d537SAndre Fischer 521ff12d537SAndre Fischer 522ff12d537SAndre Fischer 523ff12d537SAndre Fischer void ResourceManager::GetToolPanelNodeNames ( 524ff12d537SAndre Fischer ::std::vector<OUString>& rMatchingNames, 525ff12d537SAndre Fischer const ::utl::OConfigurationTreeRoot aRoot) const 526ff12d537SAndre Fischer { 527ff12d537SAndre Fischer Sequence<OUString> aChildNodeNames (aRoot.getNodeNames()); 528ff12d537SAndre Fischer const sal_Int32 nCount (aChildNodeNames.getLength()); 529ff12d537SAndre Fischer for (sal_Int32 nIndex(0); nIndex<nCount; ++nIndex) 530ff12d537SAndre Fischer { 531ff12d537SAndre Fischer if (aChildNodeNames[nIndex].matchAsciiL( 532ff12d537SAndre Fischer RTL_CONSTASCII_STRINGPARAM( "private:resource/toolpanel/"))) 533ff12d537SAndre Fischer rMatchingNames.push_back(aChildNodeNames[nIndex]); 534ff12d537SAndre Fischer } 535ff12d537SAndre Fischer } 536ff12d537SAndre Fischer 537ff12d537SAndre Fischer 538ff12d537SAndre Fischer 539ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 540