LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - PanelFactory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 40 57 70.2 %
Date: 2014-11-03 Functions: 10 10 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          38 : Reference<lang::XEventListener> mxControllerDisposeListener;
      63             : 
      64             : // ----- Service functions ----------------------------------------------------
      65             : 
      66          24 : Reference<XInterface> SAL_CALL PanelFactory_createInstance (
      67             :     const Reference<XComponentContext>& rxContext) throw (css::uno::Exception)
      68             : {
      69          24 :     return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext)));
      70             : }
      71             : 
      72          42 : ::rtl::OUString PanelFactory_getImplementationName (void) throw(RuntimeException)
      73             : {
      74          42 :     return OUString("org.openoffice.comp.Draw.framework.PanelFactory");
      75             : }
      76             : 
      77           8 : Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void)
      78             :     throw (RuntimeException)
      79             : {
      80           8 :     static const ::rtl::OUString sServiceName("com.sun.star.drawing.framework.PanelFactory");
      81           8 :     return Sequence<rtl::OUString>(&sServiceName, 1);
      82             : }
      83             : 
      84             : //----- PanelFactory --------------------------------------------------------
      85             : 
      86          24 : PanelFactory::PanelFactory(
      87             :         const css::uno::Reference<css::uno::XComponentContext>& /*rxContext*/)
      88          24 :     : PanelFactoryInterfaceBase(m_aMutex)
      89             : {
      90          24 : }
      91             : 
      92          48 : PanelFactory::~PanelFactory (void)
      93             : {
      94          48 : }
      95             : 
      96          24 : void SAL_CALL PanelFactory::disposing (void)
      97             : {
      98          24 : }
      99             : 
     100             : // XUIElementFactory
     101             : 
     102          24 : Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
     103             :     const ::rtl::OUString& rsUIElementResourceURL,
     104             :     const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
     105             :     throw(
     106             :         css::container::NoSuchElementException,
     107             :         css::lang::IllegalArgumentException,
     108             :         css::uno::RuntimeException, std::exception)
     109             : {
     110             :     // Process arguments.
     111          24 :     const ::comphelper::NamedValueCollection aArguments (rArguments);
     112          48 :     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
     113          48 :     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
     114          48 :     Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
     115             : 
     116             :     // Throw exceptions when the arguments are not as expected.
     117          24 :     vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
     118          24 :     if ( ! xParentWindow.is() || pParentWindow==NULL)
     119             :         throw RuntimeException(
     120           0 :             "PanelFactory::createUIElement called without ParentWindow");
     121          24 :     if ( ! xFrame.is())
     122             :         throw RuntimeException(
     123           0 :             "PanelFactory::createUIElement called without XFrame");
     124             : 
     125             :     // Tunnel through the controller to obtain a ViewShellBase.
     126          24 :     ViewShellBase* pBase = NULL;
     127          48 :     Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
     128          24 :     if (xTunnel.is())
     129             :     {
     130             :         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     131          24 :             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
     132          24 :         if (pController != NULL)
     133          24 :             pBase = pController->GetViewShellBase();
     134             :     }
     135          24 :     if (pBase == NULL)
     136           0 :         throw RuntimeException("can not get ViewShellBase for frame");
     137             : 
     138             :     // Get bindings from given arguments.
     139          24 :     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
     140          24 :     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
     141             : 
     142             :     // Create a framework view.
     143          24 :     vcl::Window* pControl = NULL;
     144          24 :     css::ui::LayoutSize aLayoutSize (-1,-1,-1);
     145             : 
     146             : #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
     147          24 :     if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
     148           0 :         pControl = new CustomAnimationPanel(pParentWindow, *pBase, xFrame);
     149          24 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
     150          24 :         pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar);
     151           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
     152           0 :         pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
     153           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
     154           0 :         pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
     155           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
     156           0 :         pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
     157           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
     158           0 :         pControl = new SlideTransitionPanel(pParentWindow, *pBase, xFrame);
     159           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
     160           0 :         pControl = new TableDesignPanel(pParentWindow, *pBase);
     161           0 :     else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator))
     162           0 :         pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings);
     163             : #undef EndsWith
     164             : 
     165          24 :     if (pControl == NULL)
     166           0 :         throw lang::IllegalArgumentException();
     167             : 
     168             :     // Create a wrapper around the control that implements the
     169             :     // necessary UNO interfaces.
     170             :     return sfx2::sidebar::SidebarPanelBase::Create(
     171             :         rsUIElementResourceURL,
     172             :         xFrame,
     173             :         pControl,
     174          48 :         aLayoutSize);
     175             : }
     176             : 
     177         114 : } } // end of namespace sd::sidebar
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10