LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - PanelFactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 35 52 67.3 %
Date: 2015-06-13 12:38:46 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "facreg.hxx"
      22             : #include "framework/Pane.hxx"
      23             : #include "ViewShellBase.hxx"
      24             : #include "DrawController.hxx"
      25             : #include "LayoutMenu.hxx"
      26             : #include "CurrentMasterPagesSelector.hxx"
      27             : #include "RecentMasterPagesSelector.hxx"
      28             : #include "AllMasterPagesSelector.hxx"
      29             : #include "CustomAnimationPanel.hxx"
      30             : #include "NavigatorWrapper.hxx"
      31             : #include "SlideTransitionPanel.hxx"
      32             : #include "TableDesignPanel.hxx"
      33             : 
      34             : #include <sfx2/viewfrm.hxx>
      35             : #include <sfx2/sidebar/SidebarPanelBase.hxx>
      36             : #include <comphelper/namedvaluecollection.hxx>
      37             : #include <vcl/window.hxx>
      38             : #include <toolkit/helper/vclunohelper.hxx>
      39             : 
      40             : using namespace css;
      41             : using namespace css::uno;
      42             : using namespace ::sd::framework;
      43             : using ::rtl::OUString;
      44             : 
      45             : namespace sd { namespace sidebar {
      46             : 
      47             : namespace {
      48             :     /** Note that these names have to be identical to (the tail of)
      49             :         the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
      50             :         for the TaskPanelFactory.
      51             :     */
      52             :     const static char* gsResourceNameCustomAnimations = "/CustomAnimations";
      53             :     const static char* gsResourceNameLayouts = "/Layouts";
      54             :     const static char* gsResourceNameAllMasterPages = "/AllMasterPages";
      55             :     const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages";
      56             :     const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages";
      57             :     const static char* gsResourceNameSlideTransitions = "/SlideTransitions";
      58             :     const static char* gsResourceNameTableDesign = "/TableDesign";
      59             :     const static char* gsResourceNameNavigator = "/NavigatorPanel";
      60             : }
      61             : 
      62          22 : Reference<lang::XEventListener> mxControllerDisposeListener;
      63             : 
      64             : //----- PanelFactory --------------------------------------------------------
      65             : 
      66          10 : PanelFactory::PanelFactory(
      67             :         const css::uno::Reference<css::uno::XComponentContext>& /*rxContext*/)
      68          10 :     : PanelFactoryInterfaceBase(m_aMutex)
      69             : {
      70          10 : }
      71             : 
      72          20 : PanelFactory::~PanelFactory()
      73             : {
      74          20 : }
      75             : 
      76          10 : void SAL_CALL PanelFactory::disposing()
      77             : {
      78          10 : }
      79             : 
      80             : // XUIElementFactory
      81             : 
      82          10 : Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
      83             :     const ::rtl::OUString& rsUIElementResourceURL,
      84             :     const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
      85             :     throw(
      86             :         css::container::NoSuchElementException,
      87             :         css::lang::IllegalArgumentException,
      88             :         css::uno::RuntimeException, std::exception)
      89             : {
      90             :     // Process arguments.
      91          10 :     const ::comphelper::NamedValueCollection aArguments (rArguments);
      92          20 :     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
      93          20 :     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
      94          20 :     Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
      95             : 
      96             :     // Throw exceptions when the arguments are not as expected.
      97          10 :     vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
      98          10 :     if ( ! xParentWindow.is() || pParentWindow==NULL)
      99             :         throw RuntimeException(
     100           0 :             "PanelFactory::createUIElement called without ParentWindow");
     101          10 :     if ( ! xFrame.is())
     102             :         throw RuntimeException(
     103           0 :             "PanelFactory::createUIElement called without XFrame");
     104             : 
     105             :     // Tunnel through the controller to obtain a ViewShellBase.
     106          10 :     ViewShellBase* pBase = NULL;
     107          20 :     Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
     108          10 :     if (xTunnel.is())
     109             :     {
     110             :         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     111          10 :             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
     112          10 :         if (pController != NULL)
     113          10 :             pBase = pController->GetViewShellBase();
     114             :     }
     115          10 :     if (pBase == NULL)
     116           0 :         throw RuntimeException("can not get ViewShellBase for frame");
     117             : 
     118             :     // Get bindings from given arguments.
     119          10 :     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
     120          10 :     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
     121             : 
     122             :     // Create a framework view.
     123          20 :     VclPtr<vcl::Window> pControl;
     124          10 :     css::ui::LayoutSize aLayoutSize (-1,-1,-1);
     125             : 
     126             : #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
     127          10 :     if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
     128           0 :         pControl = VclPtr<CustomAnimationPanel>::Create(pParentWindow, *pBase, xFrame);
     129          10 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
     130          10 :         pControl = VclPtr<LayoutMenu>::Create(pParentWindow, *pBase, xSidebar);
     131           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
     132           0 :         pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
     133           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
     134           0 :         pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
     135           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
     136           0 :         pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
     137           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
     138           0 :         pControl = VclPtr<SlideTransitionPanel>::Create(pParentWindow, *pBase, xFrame);
     139           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
     140           0 :         pControl = VclPtr<TableDesignPanel>::Create(pParentWindow, *pBase);
     141           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator))
     142           0 :         pControl = VclPtr<NavigatorWrapper>::Create(pParentWindow, *pBase, pBindings);
     143             : #undef EndsWith
     144             : 
     145          10 :     if (!pControl)
     146           0 :         throw lang::IllegalArgumentException();
     147             : 
     148             :     // Create a wrapper around the control that implements the
     149             :     // necessary UNO interfaces.
     150             :     return sfx2::sidebar::SidebarPanelBase::Create(
     151             :         rsUIElementResourceURL,
     152             :         xFrame,
     153             :         pControl,
     154          20 :         aLayoutSize);
     155             : }
     156             : 
     157             : } } // end of namespace sd::sidebar
     158             : 
     159             : 
     160             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     161          10 : org_openoffice_comp_Draw_framework_PanelFactory_get_implementation(::com::sun::star::uno::XComponentContext* context,
     162             :                                                                    ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     163             : {
     164          10 :     return cppu::acquire(new sd::sidebar::PanelFactory(context));
     165          66 : }
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11