Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sfx2 / source / sidebar / UnoDecks.cxx
blob6ae5e69485826695f9cf8eff6e233b090c28cde7
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 <utility>
21 #include <vcl/svapp.hxx>
23 #include <algorithm>
25 using namespace css;
26 using namespace ::sfx2::sidebar;
28 SfxUnoDecks::SfxUnoDecks(uno::Reference<frame::XFrame> _xFrame):
29 xFrame(std::move(_xFrame))
33 SidebarController* SfxUnoDecks::getSidebarController()
35 return SidebarController::GetSidebarControllerForFrame(xFrame);
38 // XNameAccess
40 uno::Any SAL_CALL SfxUnoDecks::getByName( const OUString& aName )
42 SolarMutexGuard aGuard;
44 if (!hasByName(aName))
45 throw container::NoSuchElementException();
47 uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, aName);
48 return uno::Any(xDeck);
52 uno::Sequence< OUString > SAL_CALL SfxUnoDecks::getElementNames()
54 SolarMutexGuard aGuard;
56 SidebarController* pSidebarController = getSidebarController();
58 ResourceManager::DeckContextDescriptorContainer aDecks;
59 css::uno::Sequence< OUString > deckList(aDecks.size());
61 if (pSidebarController)
63 pSidebarController->GetResourceManager()->GetMatchingDecks (
64 aDecks,
65 pSidebarController->GetCurrentContext(),
66 pSidebarController->IsDocumentReadOnly(),
67 xFrame->getController());
69 deckList.realloc(aDecks.size());
70 std::transform(aDecks.begin(), aDecks.end(), deckList.getArray(),
71 [](const auto& rDeck) { return rDeck.msId; });
74 return deckList;
78 sal_Bool SAL_CALL SfxUnoDecks::hasByName( const OUString& aName )
80 SolarMutexGuard aGuard;
82 SidebarController* pSidebarController = getSidebarController();
84 bool bFound = false;
86 if (pSidebarController)
88 ResourceManager::DeckContextDescriptorContainer aDecks;
90 pSidebarController->GetResourceManager()->GetMatchingDecks (
91 aDecks,
92 pSidebarController->GetCurrentContext(),
93 pSidebarController->IsDocumentReadOnly(),
94 xFrame->getController());
96 bFound = std::any_of(aDecks.begin(), aDecks.end(),
97 [&aName](const ResourceManager::DeckContextDescriptor& rDeck) { return rDeck.msId == aName; });
100 return bFound;
104 // XIndexAccess
106 sal_Int32 SAL_CALL SfxUnoDecks::getCount()
108 SolarMutexGuard aGuard;
110 uno::Sequence< OUString > decks = getElementNames();
111 return decks.getLength();
114 uno::Any SAL_CALL SfxUnoDecks::getByIndex( sal_Int32 Index )
116 SolarMutexGuard aGuard;
117 uno::Any aRet;
119 uno::Sequence< OUString > decks = getElementNames();
121 if (Index > decks.getLength()-1 || Index < 0)
122 throw lang::IndexOutOfBoundsException();
124 uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, decks[Index]);
125 aRet <<= xDeck;
126 return aRet;
130 // XElementAccess
131 uno::Type SAL_CALL SfxUnoDecks::getElementType()
133 return uno::Type();
136 sal_Bool SAL_CALL SfxUnoDecks::hasElements()
138 SolarMutexGuard aGuard;
140 uno::Sequence< OUString > decks = getElementNames();
141 return decks.hasElements();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */