xref: /trunk/main/sfx2/source/sidebar/Tools.cxx (revision b9e67834)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "Tools.hxx"
25 
26 #include "sfx2/sidebar/Theme.hxx"
27 
28 #include "sfx2/imagemgr.hxx"
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/componentcontext.hxx>
31 #include <comphelper/namedvaluecollection.hxx>
32 
33 
34 using namespace css;
35 using namespace cssu;
36 
37 
38 namespace sfx2 { namespace sidebar {
39 
40 Image Tools::GetImage (
41     const ::rtl::OUString& rsImageURL,
42     const ::rtl::OUString& rsHighContrastImageURL,
43     const Reference<frame::XFrame>& rxFrame)
44 {
45     if (Theme::IsHighContrastMode())
46         return GetImage(rsHighContrastImageURL, rxFrame);
47     else
48         return GetImage(rsImageURL, rxFrame);
49 }
50 
51 
52 
53 
54 Image Tools::GetImage (
55     const ::rtl::OUString& rsURL,
56     const Reference<frame::XFrame>& rxFrame)
57 {
58     if (rsURL.getLength() > 0)
59     {
60         static const sal_Char* sUnoCommandPrefix = ".uno:";
61         static const sal_Int32 nUnoCommandPrefixLength = strlen(sUnoCommandPrefix);
62         static const sal_Char* sCommandImagePrefix = "private:commandimage/";
63         static const sal_Int32 nCommandImagePrefixLength = strlen(sCommandImagePrefix);
64 
65         if (rsURL.compareToAscii(sUnoCommandPrefix, nUnoCommandPrefixLength) == 0)
66         {
67             const Image aPanelImage (::GetImage(rxFrame, rsURL, sal_False, Theme::IsHighContrastMode()));
68             return aPanelImage;
69         }
70         else if (rsURL.compareToAscii(sCommandImagePrefix, nCommandImagePrefixLength) == 0)
71         {
72             ::rtl::OUStringBuffer aCommandName;
73             aCommandName.appendAscii(sUnoCommandPrefix);
74             aCommandName.append(rsURL.copy(nCommandImagePrefixLength));
75             const ::rtl::OUString sCommandName (aCommandName.makeStringAndClear());
76 
77             const Image aPanelImage (::GetImage(rxFrame, sCommandName, sal_False, Theme::IsHighContrastMode()));
78             return aPanelImage;
79         }
80         else
81         {
82             const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory());
83             const Reference<graphic::XGraphicProvider> xGraphicProvider (
84                 aContext.createComponent("com.sun.star.graphic.GraphicProvider"),
85                 UNO_QUERY);
86             if ( xGraphicProvider.is())
87             {
88                 ::comphelper::NamedValueCollection aMediaProperties;
89                 aMediaProperties.put("URL", rsURL);
90                 const Reference<graphic::XGraphic> xGraphic (
91                     xGraphicProvider->queryGraphic(aMediaProperties.getPropertyValues()),
92                     UNO_QUERY);
93                 if (xGraphic.is())
94                     return Image(xGraphic);
95             }
96         }
97     }
98     return Image();
99 }
100 
101 
102 } } // end of namespace sfx2::sidebar
103