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>
23 using namespace ::sfx2::sidebar
;
25 SfxUnoPanels::SfxUnoPanels(const uno::Reference
<frame::XFrame
>& rFrame
, const OUString
& deckId
):
31 SidebarController
* SfxUnoPanels::getSidebarController()
33 return SidebarController::GetSidebarControllerForFrame(xFrame
);
36 OUString SAL_CALL
SfxUnoPanels::getDeckId()
38 SolarMutexGuard aGuard
;
45 uno::Any SAL_CALL
SfxUnoPanels::getByName( const OUString
& aName
)
47 SolarMutexGuard aGuard
;
49 if (!hasByName(aName
))
50 throw container::NoSuchElementException();
52 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, aName
, mDeckId
);
53 return uno::Any(xPanel
);
57 uno::Sequence
< OUString
> SAL_CALL
SfxUnoPanels::getElementNames()
60 SolarMutexGuard aGuard
;
62 SidebarController
* pSidebarController
= getSidebarController();
64 ResourceManager::PanelContextDescriptorContainer aPanels
;
65 uno::Sequence
< OUString
> panelList(aPanels
.size());
67 if (pSidebarController
)
69 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
70 pSidebarController
->GetCurrentContext(),
72 xFrame
->getController());
74 panelList
.realloc(aPanels
.size());
78 for (const auto& rPanel
: aPanels
)
80 panelList
[n
] = rPanel
.msId
;
89 sal_Bool SAL_CALL
SfxUnoPanels::hasByName( const OUString
& aName
)
91 SolarMutexGuard aGuard
;
93 SidebarController
* pSidebarController
= getSidebarController();
95 if (pSidebarController
)
97 ResourceManager::PanelContextDescriptorContainer aPanels
;
99 pSidebarController
->GetResourceManager()->GetMatchingPanels(aPanels
,
100 pSidebarController
->GetCurrentContext(),
102 xFrame
->getController());
104 bool bIsDocumentReadOnly
= pSidebarController
->IsDocumentReadOnly();
106 return std::any_of(aPanels
.begin(), aPanels
.end(),
107 [&bIsDocumentReadOnly
, &aName
](const ResourceManager::PanelContextDescriptor
& rPanel
) {
108 return (!bIsDocumentReadOnly
|| rPanel
.mbShowForReadOnlyDocuments
) // Determine if the panel can be displayed.
109 && (rPanel
.msId
== aName
);
120 sal_Int32 SAL_CALL
SfxUnoPanels::getCount()
122 SolarMutexGuard aGuard
;
124 uno::Sequence
< OUString
> panels
= getElementNames();
125 return panels
.getLength();
128 uno::Any SAL_CALL
SfxUnoPanels::getByIndex( sal_Int32 Index
)
130 SolarMutexGuard aGuard
;
134 uno::Sequence
< OUString
> panels
= getElementNames();
136 if (Index
> panels
.getLength()-1 || Index
< 0)
137 throw lang::IndexOutOfBoundsException();
139 uno::Reference
<ui::XPanel
> xPanel
= new SfxUnoPanel(xFrame
, panels
[Index
], mDeckId
);
146 uno::Type SAL_CALL
SfxUnoPanels::getElementType()
148 SolarMutexGuard aGuard
;
153 sal_Bool SAL_CALL
SfxUnoPanels::hasElements()
155 SolarMutexGuard aGuard
;
157 uno::Sequence
< OUString
> panels
= getElementNames();
158 return panels
.hasElements();
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */