1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "PanelFactory.hxx"
#include <framework/Pane.hxx>
#include <ViewShellBase.hxx>
#include <DrawController.hxx>
#include "LayoutMenu.hxx"
#include "CurrentMasterPagesSelector.hxx"
#include "RecentMasterPagesSelector.hxx"
#include "AllMasterPagesSelector.hxx"
#include "CustomAnimationPanel.hxx"
#include "NavigatorWrapper.hxx"
#include "SlideTransitionPanel.hxx"
#include "TableDesignPanel.hxx"
#include "SlideBackground.hxx"

#include <sfx2/sidebar/SidebarPanelBase.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/servicehelper.hxx>
#include <vcl/window.hxx>
#include <toolkit/helper/vclunohelper.hxx>

using namespace css;
using namespace css::uno;
using namespace ::sd::framework;

namespace sd::sidebar {

static Reference<lang::XEventListener> mxControllerDisposeListener;

//----- PanelFactory --------------------------------------------------------

PanelFactory::PanelFactory()
    : PanelFactoryInterfaceBase(m_aMutex)
{
}

PanelFactory::~PanelFactory()
{
}

void SAL_CALL PanelFactory::disposing()
{
}

// XUIElementFactory

Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
    const OUString& rsUIElementResourceURL,
    const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
{
    // Process arguments.
    const ::comphelper::NamedValueCollection aArguments (rArguments);
    Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
    Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
    Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));

    // Throw exceptions when the arguments are not as expected.
    VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
    if ( ! xParentWindow.is() || !pParentWindow)
        throw RuntimeException(
            "PanelFactory::createUIElement called without ParentWindow");
    if ( ! xFrame.is())
        throw RuntimeException(
            "PanelFactory::createUIElement called without XFrame");

    // Tunnel through the controller to obtain a ViewShellBase.
    ViewShellBase* pBase = nullptr;
    auto pController = comphelper::getUnoTunnelImplementation<sd::DrawController>(xFrame->getController());
    if (pController != nullptr)
        pBase = pController->GetViewShellBase();
    if (pBase == nullptr)
        throw RuntimeException("can not get ViewShellBase for frame");

    // Get bindings from given arguments.
    const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
    SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);

    // Create a framework view.
    VclPtr<vcl::Window> pControl;
    css::ui::LayoutSize aLayoutSize (-1,-1,-1);

    /** Note that these names have to be identical to (the tail of)
        the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
        for the TaskPanelFactory.
    */
    if (rsUIElementResourceURL.endsWith("/CustomAnimations"))
        pControl = VclPtr<CustomAnimationPanel>::Create(pParentWindow, *pBase, xFrame);
    else if (rsUIElementResourceURL.endsWith("/Layouts"))
        pControl = VclPtr<LayoutMenu>::Create(pParentWindow, *pBase, xSidebar);
    else if (rsUIElementResourceURL.endsWith("/AllMasterPages"))
        pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
    else if (rsUIElementResourceURL.endsWith("/RecentMasterPages"))
        pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
    else if (rsUIElementResourceURL.endsWith("/UsedMasterPages"))
        pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
    else if (rsUIElementResourceURL.endsWith("/SlideTransitions"))
        pControl = VclPtr<SlideTransitionPanel>::Create(pParentWindow, *pBase, xFrame);
    else if (rsUIElementResourceURL.endsWith("/TableDesign"))
        pControl = VclPtr<TableDesignPanel>::Create(pParentWindow, *pBase);
    else if (rsUIElementResourceURL.endsWith("/NavigatorPanel"))
        pControl = VclPtr<NavigatorWrapper>::Create(pParentWindow, *pBase, pBindings);
    else if (rsUIElementResourceURL.endsWith("/SlideBackgroundPanel"))
        pControl = VclPtr<SlideBackground>::Create(pParentWindow, *pBase, xFrame, pBindings);

    if (!pControl)
        throw lang::IllegalArgumentException();

    // Create a wrapper around the control that implements the
    // necessary UNO interfaces.
    return sfx2::sidebar::SidebarPanelBase::Create(
        rsUIElementResourceURL,
        xFrame,
        pControl,
        aLayoutSize);
}

} // end of namespace sd::sidebar


extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(css::uno::XComponentContext* /*context*/,<--- The function 'org_openoffice_comp_Draw_framework_PanelFactory_get_implementation' is never used.
                                                                   css::uno::Sequence<css::uno::Any> const &)
{
    return cppu::acquire(new sd::sidebar::PanelFactory);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */