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()
46 uno::Any SAL_CALL
SfxUnoPanels::getByName( const OUString
& aName
)
48 SolarMutexGuard aGuard
;
50 if (!hasByName(aName
))
51 throw container::NoSuchElementException();
53 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, aName
, mDeckId
);
54 return uno::Any(xPanel
);
58 uno::Sequence
< OUString
> SAL_CALL
SfxUnoPanels::getElementNames()
61 SolarMutexGuard aGuard
;
63 SidebarController
* pSidebarController
= getSidebarController();
65 ResourceManager::PanelContextDescriptorContainer aPanels
;
66 uno::Sequence
< OUString
> panelList(aPanels
.size());
68 if (pSidebarController
)
70 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
71 pSidebarController
->GetCurrentContext(),
73 xFrame
->getController());
75 panelList
.realloc(aPanels
.size());
76 std::transform(aPanels
.begin(), aPanels
.end(), panelList
.getArray(),
77 [](const auto& rPanel
) { return rPanel
.msId
; });
84 sal_Bool SAL_CALL
SfxUnoPanels::hasByName( const OUString
& aName
)
86 SolarMutexGuard aGuard
;
88 SidebarController
* pSidebarController
= getSidebarController();
90 if (pSidebarController
)
92 ResourceManager::PanelContextDescriptorContainer aPanels
;
94 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
95 pSidebarController
->GetCurrentContext(),
97 xFrame
->getController());
99 bool bIsDocumentReadOnly
= pSidebarController
->IsDocumentReadOnly();
101 return std::any_of(aPanels
.begin(), aPanels
.end(),
102 [&bIsDocumentReadOnly
, &aName
](const ResourceManager::PanelContextDescriptor
& rPanel
) {
103 return (!bIsDocumentReadOnly
|| rPanel
.mbShowForReadOnlyDocuments
) // Determine if the panel can be displayed.
104 && (rPanel
.msId
== aName
);
115 sal_Int32 SAL_CALL
SfxUnoPanels::getCount()
117 SolarMutexGuard aGuard
;
119 uno::Sequence
< OUString
> panels
= getElementNames();
120 return panels
.getLength();
123 uno::Any SAL_CALL
SfxUnoPanels::getByIndex( sal_Int32 Index
)
125 SolarMutexGuard aGuard
;
129 uno::Sequence
< OUString
> panels
= getElementNames();
131 if (Index
> panels
.getLength()-1 || Index
< 0)
132 throw lang::IndexOutOfBoundsException();
134 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, panels
[Index
], mDeckId
);
141 uno::Type SAL_CALL
SfxUnoPanels::getElementType()
146 sal_Bool SAL_CALL
SfxUnoPanels::hasElements()
148 SolarMutexGuard aGuard
;
150 uno::Sequence
< OUString
> panels
= getElementNames();
151 return panels
.hasElements();
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */