Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/sidebar/UnoPanels.cxx
Line
Count
Source
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
13
#include <sfx2/sidebar/ResourceManager.hxx>
14
#include <sfx2/sidebar/SidebarController.hxx>
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
25
using namespace css;
26
using namespace ::sfx2::sidebar;
27
28
SfxUnoPanels::SfxUnoPanels(uno::Reference<frame::XFrame> _xFrame, const OUString& deckId):
29
0
xFrame(std::move(_xFrame)),
30
0
mDeckId(deckId)
31
0
{
32
0
}
33
34
SidebarController* SfxUnoPanels::getSidebarController()
35
0
{
36
0
    return SidebarController::GetSidebarControllerForFrame(xFrame);
37
0
}
38
39
OUString SAL_CALL SfxUnoPanels::getDeckId()
40
0
{
41
0
    return mDeckId;
42
0
}
43
44
// XNameAccess
45
46
uno::Any SAL_CALL SfxUnoPanels::getByName( const OUString& aName )
47
0
{
48
0
    SolarMutexGuard aGuard;
49
50
0
    if (!hasByName(aName))
51
0
        throw container::NoSuchElementException();
52
53
0
    uno::Reference<ui::XPanel> xPanel = new SfxUnoPanel(xFrame, aName, mDeckId);
54
0
    return uno::Any(xPanel);
55
0
}
56
57
58
uno::Sequence< OUString > SAL_CALL SfxUnoPanels::getElementNames()
59
0
{
60
61
0
    SolarMutexGuard aGuard;
62
63
0
    SidebarController* pSidebarController = getSidebarController();
64
65
0
    ResourceManager::PanelContextDescriptorContainer aPanels;
66
0
    uno::Sequence< OUString > panelList(aPanels.size());
67
68
0
    if (pSidebarController)
69
0
    {
70
0
        pSidebarController->GetResourceManager()->GetMatchingPanels(aPanels,
71
0
                                                      pSidebarController->GetCurrentContext(),
72
0
                                                      mDeckId,
73
0
                                                      xFrame->getController());
74
75
0
        panelList.realloc(aPanels.size());
76
0
        std::transform(aPanels.begin(), aPanels.end(), panelList.getArray(),
77
0
                       [](const auto& rPanel) { return rPanel.msId; });
78
0
    }
79
80
0
    return panelList;
81
82
0
}
83
84
sal_Bool SAL_CALL SfxUnoPanels::hasByName( const OUString& aName )
85
0
{
86
0
    SolarMutexGuard aGuard;
87
88
0
    SidebarController* pSidebarController = getSidebarController();
89
90
0
    if (pSidebarController)
91
0
    {
92
0
        ResourceManager::PanelContextDescriptorContainer aPanels;
93
94
0
        pSidebarController->GetResourceManager()->GetMatchingPanels(aPanels,
95
0
                                                      pSidebarController->GetCurrentContext(),
96
0
                                                      mDeckId,
97
0
                                                      xFrame->getController());
98
99
0
        bool bIsDocumentReadOnly = pSidebarController->IsDocumentReadOnly();
100
101
0
        return std::any_of(aPanels.begin(), aPanels.end(),
102
0
            [&bIsDocumentReadOnly, &aName](const ResourceManager::PanelContextDescriptor& rPanel) {
103
0
                return (!bIsDocumentReadOnly || rPanel.mbShowForReadOnlyDocuments) // Determine if the panel can be displayed.
104
0
                    && (rPanel.msId == aName);
105
0
            });
106
0
    }
107
108
    // nothing found
109
0
    return false;
110
111
0
}
112
113
// XIndexAccess
114
115
sal_Int32 SAL_CALL SfxUnoPanels::getCount()
116
0
{
117
0
    SolarMutexGuard aGuard;
118
119
0
    uno::Sequence< OUString > panels = getElementNames();
120
0
    return panels.getLength();
121
0
}
122
123
uno::Any SAL_CALL SfxUnoPanels::getByIndex( sal_Int32 Index )
124
0
{
125
0
    SolarMutexGuard aGuard;
126
127
0
    uno::Any aRet;
128
129
0
    uno::Sequence< OUString > panels = getElementNames();
130
131
0
    if (Index > panels.getLength()-1 || Index < 0)
132
0
        throw lang::IndexOutOfBoundsException();
133
134
0
    uno::Reference<ui::XPanel> xPanel = new SfxUnoPanel(xFrame, panels[Index], mDeckId);
135
0
    aRet <<= xPanel;
136
0
    return aRet;
137
138
0
}
139
140
// XElementAccess
141
uno::Type SAL_CALL SfxUnoPanels::getElementType()
142
0
{
143
0
    return uno::Type();
144
0
}
145
146
sal_Bool SAL_CALL SfxUnoPanels::hasElements()
147
0
{
148
0
    SolarMutexGuard aGuard;
149
150
0
    uno::Sequence< OUString > panels = getElementNames();
151
0
    return panels.hasElements();
152
0
}
153
154
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */