1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
25 using namespace ::sfx2::sidebar
;
27 SfxUnoDecks::SfxUnoDecks(const uno::Reference
<frame::XFrame
>& rFrame
):
32 SidebarController
* SfxUnoDecks::getSidebarController()
34 return SidebarController::GetSidebarControllerForFrame(xFrame
);
39 uno::Any SAL_CALL
SfxUnoDecks::getByName( const OUString
& aName
)
41 SolarMutexGuard aGuard
;
43 if (!hasByName(aName
))
44 throw container::NoSuchElementException();
46 uno::Reference
<ui::XDeck
> xDeck
= new SfxUnoDeck(xFrame
, aName
);
47 return uno::Any(xDeck
);
51 uno::Sequence
< OUString
> SAL_CALL
SfxUnoDecks::getElementNames()
53 SolarMutexGuard aGuard
;
55 SidebarController
* pSidebarController
= getSidebarController();
57 ResourceManager::DeckContextDescriptorContainer aDecks
;
58 css::uno::Sequence
< OUString
> deckList(aDecks
.size());
60 if (pSidebarController
)
62 pSidebarController
->GetResourceManager()->GetMatchingDecks (
64 pSidebarController
->GetCurrentContext(),
65 pSidebarController
->IsDocumentReadOnly(),
66 xFrame
->getController());
68 deckList
.realloc(aDecks
.size());
69 std::transform(aDecks
.begin(), aDecks
.end(), deckList
.getArray(),
70 [](const auto& rDeck
) { return rDeck
.msId
; });
77 sal_Bool SAL_CALL
SfxUnoDecks::hasByName( const OUString
& aName
)
79 SolarMutexGuard aGuard
;
81 SidebarController
* pSidebarController
= getSidebarController();
85 if (pSidebarController
)
87 ResourceManager::DeckContextDescriptorContainer aDecks
;
89 pSidebarController
->GetResourceManager()->GetMatchingDecks (
91 pSidebarController
->GetCurrentContext(),
92 pSidebarController
->IsDocumentReadOnly(),
93 xFrame
->getController());
95 bFound
= std::any_of(aDecks
.begin(), aDecks
.end(),
96 [&aName
](const ResourceManager::DeckContextDescriptor
& rDeck
) { return rDeck
.msId
== aName
; });
105 sal_Int32 SAL_CALL
SfxUnoDecks::getCount()
107 SolarMutexGuard aGuard
;
109 uno::Sequence
< OUString
> decks
= getElementNames();
110 return decks
.getLength();
113 uno::Any SAL_CALL
SfxUnoDecks::getByIndex( sal_Int32 Index
)
115 SolarMutexGuard aGuard
;
118 uno::Sequence
< OUString
> decks
= getElementNames();
120 if (Index
> decks
.getLength()-1 || Index
< 0)
121 throw lang::IndexOutOfBoundsException();
123 uno::Reference
<ui::XDeck
> xDeck
= new SfxUnoDeck(xFrame
, decks
[Index
]);
130 uno::Type SAL_CALL
SfxUnoDecks::getElementType()
132 SolarMutexGuard aGuard
;
137 sal_Bool SAL_CALL
SfxUnoDecks::hasElements()
139 SolarMutexGuard aGuard
;
141 uno::Sequence
< OUString
> decks
= getElementNames();
142 return decks
.hasElements();
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */