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>
21 #include <vcl/svapp.hxx>
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
);
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 (
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
; });
78 sal_Bool SAL_CALL
SfxUnoDecks::hasByName( const OUString
& aName
)
80 SolarMutexGuard aGuard
;
82 SidebarController
* pSidebarController
= getSidebarController();
86 if (pSidebarController
)
88 ResourceManager::DeckContextDescriptorContainer aDecks
;
90 pSidebarController
->GetResourceManager()->GetMatchingDecks (
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
; });
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
;
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
]);
131 uno::Type SAL_CALL
SfxUnoDecks::getElementType()
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: */