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

Generated by: LCOV version 1.10