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>
23 using namespace ::sfx2::sidebar
;
25 SfxUnoDecks::SfxUnoDecks(const uno::Reference
<frame::XFrame
>& rFrame
):
30 SidebarController
* SfxUnoDecks::getSidebarController()
32 return SidebarController::GetSidebarControllerForFrame(xFrame
);
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 (
62 pSidebarController
->GetCurrentContext(),
63 pSidebarController
->IsDocumentReadOnly(),
64 xFrame
->getController());
66 deckList
.realloc(aDecks
.size());
70 for (const auto& rDeck
: aDecks
)
72 deckList
[n
] = rDeck
.msId
;
81 sal_Bool SAL_CALL
SfxUnoDecks::hasByName( const OUString
& aName
)
83 SolarMutexGuard aGuard
;
85 SidebarController
* pSidebarController
= getSidebarController();
89 if (pSidebarController
)
91 ResourceManager::DeckContextDescriptorContainer aDecks
;
93 pSidebarController
->GetResourceManager()->GetMatchingDecks (
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
; });
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
;
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
]);
134 uno::Type SAL_CALL
SfxUnoDecks::getElementType()
136 SolarMutexGuard aGuard
;
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: */