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 <sidebar/UnoPanels.hxx>
13 #include <sfx2/sidebar/ResourceManager.hxx>
14 #include <sfx2/sidebar/SidebarController.hxx>
16 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
17 #include <com/sun/star/ui/XPanel.hpp>
18 #include <sidebar/UnoPanel.hxx>
20 #include <vcl/svapp.hxx>
25 using namespace ::sfx2::sidebar
;
27 SfxUnoPanels::SfxUnoPanels(const uno::Reference
<frame::XFrame
>& rFrame
, const OUString
& deckId
):
33 SidebarController
* SfxUnoPanels::getSidebarController()
35 return SidebarController::GetSidebarControllerForFrame(xFrame
);
38 OUString SAL_CALL
SfxUnoPanels::getDeckId()
40 SolarMutexGuard aGuard
;
47 uno::Any SAL_CALL
SfxUnoPanels::getByName( const OUString
& aName
)
49 SolarMutexGuard aGuard
;
51 if (!hasByName(aName
))
52 throw container::NoSuchElementException();
54 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, aName
, mDeckId
);
55 return uno::Any(xPanel
);
59 uno::Sequence
< OUString
> SAL_CALL
SfxUnoPanels::getElementNames()
62 SolarMutexGuard aGuard
;
64 SidebarController
* pSidebarController
= getSidebarController();
66 ResourceManager::PanelContextDescriptorContainer aPanels
;
67 uno::Sequence
< OUString
> panelList(aPanels
.size());
69 if (pSidebarController
)
71 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
72 pSidebarController
->GetCurrentContext(),
74 xFrame
->getController());
76 panelList
.realloc(aPanels
.size());
77 std::transform(aPanels
.begin(), aPanels
.end(), panelList
.getArray(),
78 [](const auto& rPanel
) { return rPanel
.msId
; });
85 sal_Bool SAL_CALL
SfxUnoPanels::hasByName( const OUString
& aName
)
87 SolarMutexGuard aGuard
;
89 SidebarController
* pSidebarController
= getSidebarController();
91 if (pSidebarController
)
93 ResourceManager::PanelContextDescriptorContainer aPanels
;
95 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
96 pSidebarController
->GetCurrentContext(),
98 xFrame
->getController());
100 bool bIsDocumentReadOnly
= pSidebarController
->IsDocumentReadOnly();
102 return std::any_of(aPanels
.begin(), aPanels
.end(),
103 [&bIsDocumentReadOnly
, &aName
](const ResourceManager::PanelContextDescriptor
& rPanel
) {
104 return (!bIsDocumentReadOnly
|| rPanel
.mbShowForReadOnlyDocuments
) // Determine if the panel can be displayed.
105 && (rPanel
.msId
== aName
);
116 sal_Int32 SAL_CALL
SfxUnoPanels::getCount()
118 SolarMutexGuard aGuard
;
120 uno::Sequence
< OUString
> panels
= getElementNames();
121 return panels
.getLength();
124 uno::Any SAL_CALL
SfxUnoPanels::getByIndex( sal_Int32 Index
)
126 SolarMutexGuard aGuard
;
130 uno::Sequence
< OUString
> panels
= getElementNames();
132 if (Index
> panels
.getLength()-1 || Index
< 0)
133 throw lang::IndexOutOfBoundsException();
135 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, panels
[Index
], mDeckId
);
142 uno::Type SAL_CALL
SfxUnoPanels::getElementType()
144 SolarMutexGuard aGuard
;
149 sal_Bool SAL_CALL
SfxUnoPanels::hasElements()
151 SolarMutexGuard aGuard
;
153 uno::Sequence
< OUString
> panels
= getElementNames();
154 return panels
.hasElements();
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */