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>
21 #include <vcl/svapp.hxx>
26 using namespace ::sfx2::sidebar
;
28 SfxUnoPanels::SfxUnoPanels(uno::Reference
<frame::XFrame
> _xFrame
, const OUString
& deckId
):
29 xFrame(std::move(_xFrame
)),
34 SidebarController
* SfxUnoPanels::getSidebarController()
36 return SidebarController::GetSidebarControllerForFrame(xFrame
);
39 OUString SAL_CALL
SfxUnoPanels::getDeckId()
41 SolarMutexGuard aGuard
;
48 uno::Any SAL_CALL
SfxUnoPanels::getByName( const OUString
& aName
)
50 SolarMutexGuard aGuard
;
52 if (!hasByName(aName
))
53 throw container::NoSuchElementException();
55 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, aName
, mDeckId
);
56 return uno::Any(xPanel
);
60 uno::Sequence
< OUString
> SAL_CALL
SfxUnoPanels::getElementNames()
63 SolarMutexGuard aGuard
;
65 SidebarController
* pSidebarController
= getSidebarController();
67 ResourceManager::PanelContextDescriptorContainer aPanels
;
68 uno::Sequence
< OUString
> panelList(aPanels
.size());
70 if (pSidebarController
)
72 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
73 pSidebarController
->GetCurrentContext(),
75 xFrame
->getController());
77 panelList
.realloc(aPanels
.size());
78 std::transform(aPanels
.begin(), aPanels
.end(), panelList
.getArray(),
79 [](const auto& rPanel
) { return rPanel
.msId
; });
86 sal_Bool SAL_CALL
SfxUnoPanels::hasByName( const OUString
& aName
)
88 SolarMutexGuard aGuard
;
90 SidebarController
* pSidebarController
= getSidebarController();
92 if (pSidebarController
)
94 ResourceManager::PanelContextDescriptorContainer aPanels
;
96 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
97 pSidebarController
->GetCurrentContext(),
99 xFrame
->getController());
101 bool bIsDocumentReadOnly
= pSidebarController
->IsDocumentReadOnly();
103 return std::any_of(aPanels
.begin(), aPanels
.end(),
104 [&bIsDocumentReadOnly
, &aName
](const ResourceManager::PanelContextDescriptor
& rPanel
) {
105 return (!bIsDocumentReadOnly
|| rPanel
.mbShowForReadOnlyDocuments
) // Determine if the panel can be displayed.
106 && (rPanel
.msId
== aName
);
117 sal_Int32 SAL_CALL
SfxUnoPanels::getCount()
119 SolarMutexGuard aGuard
;
121 uno::Sequence
< OUString
> panels
= getElementNames();
122 return panels
.getLength();
125 uno::Any SAL_CALL
SfxUnoPanels::getByIndex( sal_Int32 Index
)
127 SolarMutexGuard aGuard
;
131 uno::Sequence
< OUString
> panels
= getElementNames();
133 if (Index
> panels
.getLength()-1 || Index
< 0)
134 throw lang::IndexOutOfBoundsException();
136 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, panels
[Index
], mDeckId
);
143 uno::Type SAL_CALL
SfxUnoPanels::getElementType()
148 sal_Bool SAL_CALL
SfxUnoPanels::hasElements()
150 SolarMutexGuard aGuard
;
152 uno::Sequence
< OUString
> panels
= getElementNames();
153 return panels
.hasElements();
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */