LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - Tools.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 57 69 82.6 %
Date: 2015-06-13 12:38:46 Functions: 7 7 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 <sfx2/sidebar/Tools.hxx>
      21             : 
      22             : #include <sfx2/sidebar/Theme.hxx>
      23             : 
      24             : #include <sfx2/imagemgr.hxx>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <comphelper/namedvaluecollection.hxx>
      27             : #include <vcl/gradient.hxx>
      28             : 
      29             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      30             : #include <com/sun/star/graphic/GraphicProvider.hpp>
      31             : #include <com/sun/star/util/URLTransformer.hpp>
      32             : #include <com/sun/star/frame/ModuleManager.hpp>
      33             : 
      34             : #include <cstring>
      35             : 
      36             : using namespace css;
      37             : using namespace css::uno;
      38             : 
      39             : namespace sfx2 { namespace sidebar {
      40             : 
      41        3020 : Image Tools::GetImage (
      42             :     const ::rtl::OUString& rsImageURL,
      43             :     const ::rtl::OUString& rsHighContrastImageURL,
      44             :     const Reference<frame::XFrame>& rxFrame)
      45             : {
      46        3020 :     if (Theme::IsHighContrastMode())
      47           0 :         return GetImage(rsHighContrastImageURL, rxFrame);
      48             :     else
      49        3020 :         return GetImage(rsImageURL, rxFrame);
      50             : }
      51             : 
      52       11937 : Image Tools::GetImage (
      53             :     const ::rtl::OUString& rsURL,
      54             :     const Reference<frame::XFrame>& rxFrame)
      55             : {
      56       11937 :     if (rsURL.getLength() > 0)
      57             :     {
      58        3796 :         const sal_Char  sUnoCommandPrefix[] = ".uno:";
      59        3796 :         const sal_Char  sCommandImagePrefix[] = "private:commandimage/";
      60        3796 :         const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix);
      61             : 
      62        3796 :         if (rsURL.startsWith(sUnoCommandPrefix))
      63             :         {
      64           0 :             const Image aPanelImage (::GetImage(rxFrame, rsURL, false));
      65           0 :             return aPanelImage;
      66             :         }
      67        3796 :         else if (rsURL.startsWith(sCommandImagePrefix))
      68             :         {
      69           0 :             ::rtl::OUStringBuffer aCommandName;
      70           0 :             aCommandName.appendAscii(sUnoCommandPrefix);
      71           0 :             aCommandName.append(rsURL.copy(nCommandImagePrefixLength));
      72           0 :             const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear());
      73             : 
      74           0 :             const Image aPanelImage (::GetImage(rxFrame, sCommandName, false));
      75           0 :             return aPanelImage;
      76             :         }
      77             :         else
      78             :         {
      79        3796 :             const Reference<XComponentContext> xContext (::comphelper::getProcessComponentContext());
      80             :             const Reference<graphic::XGraphicProvider> xGraphicProvider =
      81        3796 :                 graphic::GraphicProvider::create( xContext );
      82        3796 :             ::comphelper::NamedValueCollection aMediaProperties;
      83        3796 :             aMediaProperties.put("URL", rsURL);
      84             :             const Reference<graphic::XGraphic> xGraphic (
      85        3796 :                 xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()),
      86        3796 :                 UNO_QUERY);
      87        3796 :             if (xGraphic.is())
      88        3796 :                 return Image(xGraphic);
      89             :         }
      90             :     }
      91        8141 :     return Image();
      92             : }
      93             : 
      94         200 : css::awt::Gradient Tools::VclToAwtGradient (const Gradient& rVclGradient)
      95             : {
      96             :     css::awt::Gradient aAwtGradient (
      97         200 :         awt::GradientStyle(rVclGradient.GetStyle()),
      98         200 :         rVclGradient.GetStartColor().GetRGBColor(),
      99         200 :         rVclGradient.GetEndColor().GetRGBColor(),
     100         200 :         rVclGradient.GetAngle(),
     101         200 :         rVclGradient.GetBorder(),
     102         200 :         rVclGradient.GetOfsX(),
     103         200 :         rVclGradient.GetOfsY(),
     104         200 :         rVclGradient.GetStartIntensity(),
     105         200 :         rVclGradient.GetEndIntensity(),
     106        2000 :         rVclGradient.GetSteps());
     107         200 :     return aAwtGradient;
     108             : }
     109             : 
     110         194 : Gradient Tools::AwtToVclGradient (const css::awt::Gradient& rAwtGradient)
     111             : {
     112             :     Gradient aVclGradient (
     113             :         GradientStyle(rAwtGradient.Style),
     114             :         rAwtGradient.StartColor,
     115         194 :         rAwtGradient.EndColor);
     116         194 :     aVclGradient.SetAngle(rAwtGradient.Angle);
     117         194 :     aVclGradient.SetBorder(rAwtGradient.Border);
     118         194 :     aVclGradient.SetOfsX(rAwtGradient.XOffset);
     119         194 :     aVclGradient.SetOfsY(rAwtGradient.YOffset);
     120         194 :     aVclGradient.SetStartIntensity(rAwtGradient.StartIntensity);
     121         194 :     aVclGradient.SetEndIntensity(rAwtGradient.EndIntensity);
     122         194 :     aVclGradient.SetSteps(rAwtGradient.StepCount);
     123             : 
     124         194 :     return aVclGradient;
     125             : }
     126             : 
     127       24191 : util::URL Tools::GetURL (const ::rtl::OUString& rsCommand)
     128             : {
     129       24191 :     util::URL aURL;
     130       24191 :     aURL.Complete = rsCommand;
     131             : 
     132       48382 :     const Reference<XComponentContext> xComponentContext (::comphelper::getProcessComponentContext());
     133       48382 :     const Reference<util::XURLTransformer> xParser = util::URLTransformer::create( xComponentContext );
     134       24191 :     xParser->parseStrict(aURL);
     135             : 
     136       48382 :     return aURL;
     137             : }
     138             : 
     139        3155 : Reference<frame::XDispatch> Tools::GetDispatch (
     140             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
     141             :     const util::URL& rURL)
     142             : {
     143        3155 :     Reference<frame::XDispatchProvider> xProvider (rxFrame, UNO_QUERY_THROW);
     144        3155 :     Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(rURL, ::rtl::OUString(), 0));
     145        3155 :     return xDispatch;
     146             : }
     147             : 
     148       25475 : ::rtl::OUString Tools::GetModuleName (
     149             :     const css::uno::Reference<css::frame::XFrame>& rxFrame)
     150             : {
     151       25475 :     if ( ! rxFrame.is() || ! rxFrame->getController().is())
     152           0 :         return ::rtl::OUString();
     153             : 
     154             :     try
     155             :     {
     156       25475 :         const Reference<XComponentContext> xComponentContext (::comphelper::getProcessComponentContext());
     157       50950 :         const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xComponentContext );
     158       50950 :         return xModuleManager->identify(rxFrame);
     159             :     }
     160           0 :     catch (const Exception&)
     161             :     {
     162             :         // Ignored.
     163             :     }
     164           0 :     return ::rtl::OUString();
     165             : }
     166             : 
     167             : } } // end of namespace sfx2::sidebar
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11