Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/sidebar/PanelFactory.cxx
Line
Count
Source (jump to first uncovered line)
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
20
#include "PanelFactory.hxx"
21
#include <framework/Pane.hxx>
22
#include <ViewShellBase.hxx>
23
#include <DrawController.hxx>
24
#include "LayoutMenu.hxx"
25
#include "CurrentMasterPagesSelector.hxx"
26
#include "RecentMasterPagesSelector.hxx"
27
#include "AllMasterPagesSelector.hxx"
28
#include <CustomAnimationPane.hxx>
29
#include "NavigatorWrapper.hxx"
30
#include <SlideTransitionPane.hxx>
31
#include <TableDesignPane.hxx>
32
#include "SlideBackground.hxx"
33
34
#include <sfx2/sidebar/SidebarPanelBase.hxx>
35
#include <com/sun/star/uno/XComponentContext.hpp>
36
#include <comphelper/namedvaluecollection.hxx>
37
#include <comphelper/servicehelper.hxx>
38
#include <cppuhelper/supportsservice.hxx>
39
#include <vcl/weldutils.hxx>
40
41
using namespace css;
42
using namespace css::uno;
43
44
namespace sd::sidebar {
45
46
//----- PanelFactory --------------------------------------------------------
47
48
PanelFactory::PanelFactory()
49
0
{
50
0
}
Unexecuted instantiation: sd::sidebar::PanelFactory::PanelFactory()
Unexecuted instantiation: sd::sidebar::PanelFactory::PanelFactory()
51
52
PanelFactory::~PanelFactory()
53
0
{
54
0
}
55
56
// XUIElementFactory
57
58
Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
59
    const OUString& rsUIElementResourceURL,
60
    const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
61
0
{
62
    // Process arguments.
63
0
    const ::comphelper::NamedValueCollection aArguments (rArguments);
64
0
    Reference<frame::XFrame> xFrame (aArguments.getOrDefault(u"Frame"_ustr, Reference<frame::XFrame>()));
65
0
    Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault(u"ParentWindow"_ustr, Reference<awt::XWindow>()));
66
0
    Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault(u"Sidebar"_ustr, Reference<ui::XSidebar>()));
67
68
    // Throw exceptions when the arguments are not as expected.
69
0
    weld::Widget* pParent(nullptr);
70
0
    if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get()))
71
0
        pParent = pTunnel->getWidget();
72
73
0
    if (!pParent)
74
0
        throw RuntimeException(
75
0
            u"PanelFactory::createUIElement called without ParentWindow"_ustr);
76
0
    if ( ! xFrame.is())
77
0
        throw RuntimeException(
78
0
            u"PanelFactory::createUIElement called without XFrame"_ustr);
79
80
    // Tunnel through the controller to obtain a ViewShellBase.
81
0
    ViewShellBase* pBase = nullptr;
82
0
    rtl::Reference<sd::DrawController> pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get());
83
0
    if (pController != nullptr)
84
0
        pBase = pController->GetViewShellBase();
85
0
    if (pBase == nullptr)
86
0
        throw RuntimeException(u"can not get ViewShellBase for frame"_ustr);
87
88
    // Get bindings from given arguments.
89
0
    const sal_uInt64 nBindingsValue (aArguments.getOrDefault(u"SfxBindings"_ustr, sal_uInt64(0)));
90
0
    SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
91
92
    // Create a framework view.
93
0
    std::unique_ptr<PanelLayout> xControl;
94
0
    css::ui::LayoutSize aLayoutSize (-1,-1,-1);
95
96
    /** Note that these names have to be identical to (the tail of)
97
        the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
98
        for the TaskPanelFactory.
99
    */
100
0
    if (rsUIElementResourceURL.endsWith("/CustomAnimations"))
101
0
        xControl = std::make_unique<CustomAnimationPane>(pParent, *pBase);
102
0
    else if (rsUIElementResourceURL.endsWith("/Layouts"))
103
0
        xControl = std::make_unique<LayoutMenu>(pParent, *pBase, xSidebar);
104
0
    else if (rsUIElementResourceURL.endsWith("/AllMasterPages"))
105
0
        xControl = AllMasterPagesSelector::Create(pParent, *pBase, xSidebar);
106
0
    else if (rsUIElementResourceURL.endsWith("/RecentMasterPages"))
107
0
        xControl = RecentMasterPagesSelector::Create(pParent, *pBase, xSidebar);
108
0
    else if (rsUIElementResourceURL.endsWith("/UsedMasterPages"))
109
0
        xControl = CurrentMasterPagesSelector::Create(pParent, *pBase, xSidebar);
110
0
    else if (rsUIElementResourceURL.endsWith("/SlideTransitions"))
111
0
        xControl = std::make_unique<SlideTransitionPane>(pParent, *pBase);
112
0
    else if (rsUIElementResourceURL.endsWith("/TableDesign"))
113
0
        xControl = std::make_unique<TableDesignPane>(pParent, *pBase);
114
0
    else if (rsUIElementResourceURL.endsWith("/NavigatorPanel"))
115
0
        xControl = std::make_unique<NavigatorWrapper>(pParent, *pBase, pBindings);
116
0
    else if (rsUIElementResourceURL.endsWith("/SlideBackgroundPanel"))
117
0
        xControl = std::make_unique<SlideBackground>(pParent, *pBase, xFrame, pBindings);
118
119
0
    if (!xControl)
120
0
        throw lang::IllegalArgumentException();
121
122
    // Create a wrapper around the control that implements the
123
    // necessary UNO interfaces.
124
0
    return sfx2::sidebar::SidebarPanelBase::Create(
125
0
        rsUIElementResourceURL,
126
0
        xFrame,
127
0
        std::move(xControl),
128
0
        aLayoutSize);
129
0
}
130
131
0
OUString PanelFactory::getImplementationName() {
132
0
    return u"org.openoffice.comp.Draw.framework.PanelFactory"_ustr;
133
0
}
134
135
0
sal_Bool PanelFactory::supportsService(OUString const & ServiceName) {
136
0
    return cppu::supportsService(this, ServiceName);
137
0
}
138
139
0
css::uno::Sequence<OUString> PanelFactory::getSupportedServiceNames() {
140
0
    return {u"com.sun.star.drawing.framework.PanelFactory"_ustr};
141
0
}
142
143
} // end of namespace sd::sidebar
144
145
146
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
147
org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(css::uno::XComponentContext* /*context*/,
148
                                                                   css::uno::Sequence<css::uno::Any> const &)
149
0
{
150
0
    return cppu::acquire(new sd::sidebar::PanelFactory);
151
0
}
152
153
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */