Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/sidebar/SidebarPanelBase.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
#include <sfx2/sidebar/SidebarPanelBase.hxx>
20
#include <sfx2/sidebar/ILayoutableWindow.hxx>
21
#include <sfx2/sidebar/IContextChangeReceiver.hxx>
22
#include <sfx2/sidebar/PanelLayout.hxx>
23
#include <sfx2/sidebar/SidebarModelUpdate.hxx>
24
#include <utility>
25
#include <vcl/EnumContext.hxx>
26
#include <vcl/svapp.hxx>
27
#include <comphelper/processfactory.hxx>
28
#include <comphelper/namedvaluecollection.hxx>
29
#include <com/sun/star/awt/XWindowPeer.hpp>
30
#include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
31
#include <com/sun/star/ui/UIElementType.hpp>
32
33
using namespace css;
34
using namespace css::uno;
35
36
namespace sfx2::sidebar {
37
38
Reference<ui::XUIElement> SidebarPanelBase::Create (
39
    const OUString& rsResourceURL,
40
    const css::uno::Reference<css::frame::XFrame>& rxFrame,
41
    std::unique_ptr<PanelLayout> xControl,
42
    const css::ui::LayoutSize& rLayoutSize)
43
0
{
44
0
    Reference<ui::XUIElement> xUIElement (
45
0
        new SidebarPanelBase(
46
0
            rsResourceURL,
47
0
            rxFrame,
48
0
            std::move(xControl),
49
0
            rLayoutSize));
50
0
    return xUIElement;
51
0
}
52
53
SidebarPanelBase::SidebarPanelBase (
54
    OUString sResourceURL,
55
    css::uno::Reference<css::frame::XFrame> xFrame,
56
    std::unique_ptr<PanelLayout> xControl,
57
    const css::ui::LayoutSize& rLayoutSize)
58
0
    : mxFrame(std::move(xFrame)),
59
0
      mxControl(std::move(xControl)),
60
0
      msResourceURL(std::move(sResourceURL)),
61
0
      maLayoutSize(rLayoutSize)
62
0
{
63
0
    if (mxFrame.is())
64
0
    {
65
0
        css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
66
0
            css::ui::ContextChangeEventMultiplexer::get(
67
0
                ::comphelper::getProcessComponentContext()));
68
0
        xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
69
0
    }
70
0
}
Unexecuted instantiation: sfx2::sidebar::SidebarPanelBase::SidebarPanelBase(rtl::OUString, com::sun::star::uno::Reference<com::sun::star::frame::XFrame>, std::__1::unique_ptr<PanelLayout, std::__1::default_delete<PanelLayout> >, com::sun::star::ui::LayoutSize const&)
Unexecuted instantiation: sfx2::sidebar::SidebarPanelBase::SidebarPanelBase(rtl::OUString, com::sun::star::uno::Reference<com::sun::star::frame::XFrame>, std::__1::unique_ptr<PanelLayout, std::__1::default_delete<PanelLayout> >, com::sun::star::ui::LayoutSize const&)
71
72
SidebarPanelBase::~SidebarPanelBase()
73
0
{
74
0
}
75
76
void SidebarPanelBase::SetParentPanel(sfx2::sidebar::Panel* pPanel)
77
0
{
78
0
    if (!mxControl)
79
0
        return;
80
0
    mxControl->SetPanel(pPanel);
81
0
}
82
83
void SidebarPanelBase::disposing(std::unique_lock<std::mutex>&)
84
0
{
85
0
    SolarMutexGuard aGuard;
86
87
0
    mxControl.reset();
88
89
0
    if (mxFrame.is())
90
0
    {
91
0
        css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
92
0
            css::ui::ContextChangeEventMultiplexer::get(
93
0
                ::comphelper::getProcessComponentContext()));
94
0
        xMultiplexer->removeAllContextChangeEventListeners(this);
95
0
        mxFrame = nullptr;
96
0
    }
97
0
}
98
99
// XContextChangeEventListener
100
void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
101
    const ui::ContextChangeEventObject& rEvent)
102
0
{
103
0
    SolarMutexGuard aGuard;
104
105
0
    IContextChangeReceiver* pContextChangeReceiver
106
0
        = dynamic_cast<IContextChangeReceiver*>(mxControl.get());
107
0
    if (pContextChangeReceiver != nullptr)
108
0
    {
109
0
        const vcl::EnumContext aContext(
110
0
            vcl::EnumContext::GetApplicationEnum(rEvent.ApplicationName),
111
0
            vcl::EnumContext::GetContextEnum(rEvent.ContextName));
112
0
        pContextChangeReceiver->HandleContextChange(aContext);
113
0
    }
114
0
}
115
116
void SAL_CALL SidebarPanelBase::disposing (
117
    const css::lang::EventObject&)
118
0
{
119
0
    SolarMutexGuard aGuard;
120
121
0
    mxFrame = nullptr;
122
0
    mxControl.reset();
123
0
}
124
125
css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
126
0
{
127
0
    return mxFrame;
128
0
}
129
130
OUString SAL_CALL SidebarPanelBase::getResourceURL()
131
0
{
132
0
    return msResourceURL;
133
0
}
134
135
sal_Int16 SAL_CALL SidebarPanelBase::getType()
136
0
{
137
0
    return ui::UIElementType::TOOLPANEL;
138
0
}
139
140
Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
141
0
{
142
0
    return getXWeak();
143
0
}
144
145
Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
146
    const Reference<accessibility::XAccessible>&)
147
0
{
148
    // Not implemented.
149
0
    return nullptr;
150
0
}
151
152
Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
153
0
{
154
    // Not implemented
155
0
    return nullptr;
156
0
}
157
158
ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
159
0
{
160
0
    SolarMutexGuard aGuard;
161
162
0
    if (maLayoutSize.Minimum >= 0)
163
0
        return maLayoutSize;
164
165
0
    ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mxControl.get());
166
0
    if (pLayoutableWindow)
167
0
        return pLayoutableWindow->GetHeightForWidth(nWidth);
168
0
    else
169
0
    {
170
        // widget layout-based sidebar
171
0
        mxControl->queue_resize();
172
0
        Size aSize(mxControl->get_preferred_size());
173
0
        return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
174
0
    }
175
0
}
176
177
sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth ()
178
0
{
179
0
    SolarMutexGuard aGuard;
180
181
    // widget layout-based sidebar
182
0
    Size aSize(mxControl->get_preferred_size());
183
0
    return aSize.Width();
184
0
}
185
186
void SAL_CALL SidebarPanelBase::updateModel(const css::uno::Reference<css::frame::XModel>& xModel)
187
0
{
188
0
    SolarMutexGuard aGuard;
189
190
0
    SidebarModelUpdate* pModelUpdate = dynamic_cast<SidebarModelUpdate*>(mxControl.get());
191
0
    if (!pModelUpdate)
192
0
        return;
193
194
0
    pModelUpdate->updateModel(xModel);
195
0
}
196
197
Reference<css::frame::XFrame> GetFrame(const comphelper::NamedValueCollection& rArguments)
198
0
{
199
0
    Reference<css::frame::XController> xController(rArguments.getOrDefault(u"Controller"_ustr, Reference<css::frame::XController>()));
200
0
    Reference<frame::XFrame> xFrame(xController ? xController->getFrame() : nullptr);
201
0
    if (!xFrame)
202
0
        xFrame = rArguments.getOrDefault(u"Frame"_ustr, Reference<frame::XFrame>());
203
0
    return xFrame;
204
0
}
205
206
} // end of namespace sfx2::sidebar
207
208
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */