nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / sidebar / UnoDecks.cxx
blob519840698df501ed40f7bb7592167cc32ba5c4f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 */
11 #include <sal/config.h>
13 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
14 #include <sidebar/UnoDecks.hxx>
15 #include <sidebar/UnoDeck.hxx>
17 #include <sfx2/sidebar/ResourceManager.hxx>
18 #include <sfx2/sidebar/SidebarController.hxx>
20 #include <vcl/svapp.hxx>
22 using namespace css;
23 using namespace ::sfx2::sidebar;
25 SfxUnoDecks::SfxUnoDecks(const uno::Reference<frame::XFrame>& rFrame):
26 xFrame(rFrame)
30 SidebarController* SfxUnoDecks::getSidebarController()
32 return SidebarController::GetSidebarControllerForFrame(xFrame);
35 // XNameAccess
37 uno::Any SAL_CALL SfxUnoDecks::getByName( const OUString& aName )
39 SolarMutexGuard aGuard;
41 if (!hasByName(aName))
42 throw container::NoSuchElementException();
44 uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, aName);
45 return uno::Any(xDeck);
49 uno::Sequence< OUString > SAL_CALL SfxUnoDecks::getElementNames()
51 SolarMutexGuard aGuard;
53 SidebarController* pSidebarController = getSidebarController();
55 ResourceManager::DeckContextDescriptorContainer aDecks;
56 css::uno::Sequence< OUString > deckList(aDecks.size());
58 if (pSidebarController)
60 pSidebarController->GetResourceManager()->GetMatchingDecks (
61 aDecks,
62 pSidebarController->GetCurrentContext(),
63 pSidebarController->IsDocumentReadOnly(),
64 xFrame->getController());
66 deckList.realloc(aDecks.size());
68 tools::Long n = 0;
70 for (const auto& rDeck : aDecks)
72 deckList[n] = rDeck.msId;
73 n++;
77 return deckList;
81 sal_Bool SAL_CALL SfxUnoDecks::hasByName( const OUString& aName )
83 SolarMutexGuard aGuard;
85 SidebarController* pSidebarController = getSidebarController();
87 bool bFound = false;
89 if (pSidebarController)
91 ResourceManager::DeckContextDescriptorContainer aDecks;
93 pSidebarController->GetResourceManager()->GetMatchingDecks (
94 aDecks,
95 pSidebarController->GetCurrentContext(),
96 pSidebarController->IsDocumentReadOnly(),
97 xFrame->getController());
99 bFound = std::any_of(aDecks.begin(), aDecks.end(),
100 [&aName](const ResourceManager::DeckContextDescriptor& rDeck) { return rDeck.msId == aName; });
103 return bFound;
107 // XIndexAccess
109 sal_Int32 SAL_CALL SfxUnoDecks::getCount()
111 SolarMutexGuard aGuard;
113 uno::Sequence< OUString > decks = getElementNames();
114 return decks.getLength();
117 uno::Any SAL_CALL SfxUnoDecks::getByIndex( sal_Int32 Index )
119 SolarMutexGuard aGuard;
120 uno::Any aRet;
122 uno::Sequence< OUString > decks = getElementNames();
124 if (Index > decks.getLength()-1 || Index < 0)
125 throw lang::IndexOutOfBoundsException();
127 uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, decks[Index]);
128 aRet <<= xDeck;
129 return aRet;
133 // XElementAccess
134 uno::Type SAL_CALL SfxUnoDecks::getElementType()
136 SolarMutexGuard aGuard;
138 return uno::Type();
141 sal_Bool SAL_CALL SfxUnoDecks::hasElements()
143 SolarMutexGuard aGuard;
145 uno::Sequence< OUString > decks = getElementNames();
146 return decks.hasElements();
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */