Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / UnoPanels.cxx
bloba35c559f3e816aa03468e7885c9027e59f1cd1a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
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>
22 using namespace css;
23 using namespace ::sfx2::sidebar;
25 SfxUnoPanels::SfxUnoPanels(const uno::Reference<frame::XFrame>& rFrame, const OUString& deckId):
26 xFrame(rFrame),
27 mDeckId(deckId)
31 SidebarController* SfxUnoPanels::getSidebarController()
33 return SidebarController::GetSidebarControllerForFrame(xFrame);
36 OUString SAL_CALL SfxUnoPanels::getDeckId()
38 SolarMutexGuard aGuard;
40 return mDeckId;
43 // XNameAccess
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(),
71 mDeckId,
72 xFrame->getController());
74 panelList.realloc(aPanels.size());
76 tools::Long n = 0;
78 for (const auto& rPanel : aPanels)
80 panelList[n] = rPanel.msId;
81 n++;
85 return panelList;
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(),
101 mDeckId,
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);
113 // nothing found
114 return false;
118 // XIndexAccess
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;
132 uno::Any aRet;
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);
140 aRet <<= xPanel;
141 return aRet;
145 // XElementAccess
146 uno::Type SAL_CALL SfxUnoPanels::getElementType()
148 SolarMutexGuard aGuard;
150 return uno::Type();
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: */