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