LibreOffice Module sfx2 (master) 1
UnoPanels.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#include <sidebar/UnoPanels.hxx>
12
15
16#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
17#include <com/sun/star/ui/XPanel.hpp>
18#include <sidebar/UnoPanel.hxx>
19
20#include <utility>
21#include <vcl/svapp.hxx>
22
23#include <algorithm>
24
25using namespace css;
26using namespace ::sfx2::sidebar;
27
28SfxUnoPanels::SfxUnoPanels(uno::Reference<frame::XFrame> _xFrame, const OUString& deckId):
29xFrame(std::move(_xFrame)),
30mDeckId(deckId)
31{
32}
33
35{
36 return SidebarController::GetSidebarControllerForFrame(xFrame);
37}
38
39OUString SAL_CALL SfxUnoPanels::getDeckId()
40{
41 SolarMutexGuard aGuard;
42
43 return mDeckId;
44}
45
46// XNameAccess
47
48uno::Any SAL_CALL SfxUnoPanels::getByName( const OUString& aName )
49{
50 SolarMutexGuard aGuard;
51
52 if (!hasByName(aName))
53 throw container::NoSuchElementException();
54
55 uno::Reference<ui::XPanel> xPanel = new SfxUnoPanel(xFrame, aName, mDeckId);
56 return uno::Any(xPanel);
57}
58
59
60uno::Sequence< OUString > SAL_CALL SfxUnoPanels::getElementNames()
61{
62
63 SolarMutexGuard aGuard;
64
65 SidebarController* pSidebarController = getSidebarController();
66
67 ResourceManager::PanelContextDescriptorContainer aPanels;
68 uno::Sequence< OUString > panelList(aPanels.size());
69
70 if (pSidebarController)
71 {
72 pSidebarController->GetResourceManager()->GetMatchingPanels(aPanels,
73 pSidebarController->GetCurrentContext(),
74 mDeckId,
75 xFrame->getController());
76
77 panelList.realloc(aPanels.size());
78 std::transform(aPanels.begin(), aPanels.end(), panelList.getArray(),
79 [](const auto& rPanel) { return rPanel.msId; });
80 }
81
82 return panelList;
83
84}
85
86sal_Bool SAL_CALL SfxUnoPanels::hasByName( const OUString& aName )
87{
88 SolarMutexGuard aGuard;
89
90 SidebarController* pSidebarController = getSidebarController();
91
92 if (pSidebarController)
93 {
94 ResourceManager::PanelContextDescriptorContainer aPanels;
95
96 pSidebarController->GetResourceManager()->GetMatchingPanels(aPanels,
97 pSidebarController->GetCurrentContext(),
98 mDeckId,
99 xFrame->getController());
100
101 bool bIsDocumentReadOnly = pSidebarController->IsDocumentReadOnly();
102
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);
107 });
108 }
109
110 // nothing found
111 return false;
112
113}
114
115// XIndexAccess
116
117sal_Int32 SAL_CALL SfxUnoPanels::getCount()
118{
119 SolarMutexGuard aGuard;
120
121 uno::Sequence< OUString > panels = getElementNames();
122 return panels.getLength();
123}
124
126{
127 SolarMutexGuard aGuard;
128
129 uno::Any aRet;
130
131 uno::Sequence< OUString > panels = getElementNames();
132
133 if (Index > panels.getLength()-1 || Index < 0)
134 throw lang::IndexOutOfBoundsException();
135
136 uno::Reference<ui::XPanel> xPanel = new SfxUnoPanel(xFrame, panels[Index], mDeckId);
137 aRet <<= xPanel;
138 return aRet;
139
140}
141
142// XElementAccess
144{
145 return uno::Type();
146}
147
149{
150 SolarMutexGuard aGuard;
151
152 uno::Sequence< OUString > panels = getElementNames();
153 return panels.hasElements();
154}
155
156/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
get the Panel
Definition: UnoPanel.hxx:30
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: UnoPanels.cxx:60
const css::uno::Reference< css::frame::XFrame > xFrame
Definition: UnoPanels.hxx:51
virtual sal_Bool SAL_CALL hasElements() override
Definition: UnoPanels.cxx:148
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: UnoPanels.cxx:48
sfx2::sidebar::SidebarController * getSidebarController()
Definition: UnoPanels.cxx:34
SfxUnoPanels(css::uno::Reference< css::frame::XFrame >, const OUString &)
Definition: UnoPanels.cxx:28
virtual sal_Int32 SAL_CALL getCount() override
Definition: UnoPanels.cxx:117
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: UnoPanels.cxx:125
virtual css::uno::Type SAL_CALL getElementType() override
Definition: UnoPanels.cxx:143
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: UnoPanels.cxx:86
const OUString & mDeckId
Definition: UnoPanels.hxx:53
virtual OUString SAL_CALL getDeckId() override
Definition: UnoPanels.cxx:39
OUString aName
Reference< XFrame > xFrame
unsigned char sal_Bool