LibreOffice Module vcl (master)  1
implimagetree.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_VCL_INC_IMPLIMAGETREE_HXX
21 #define INCLUDED_VCL_INC_IMPLIMAGETREE_HXX
22 
23 #include <sal/config.h>
24 
25 #include <memory>
26 #include <unordered_map>
27 #include <utility>
28 #include <vector>
29 
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <rtl/ustring.hxx>
32 #include <vcl/bitmapex.hxx>
34 #include <vcl/ImageTree.hxx>
35 
36 namespace com { namespace sun { namespace star { namespace container {
37  class XNameAccess;
38 }}}}
39 
41 {
42  OUString msName;
43  OUString const msStyle;
48  sal_Int32 mnScalePercentage;
49 
50  ImageRequestParameters(const OUString & rName, const OUString & rStyle, BitmapEx& rBitmap, bool bLocalized,
51  ImageLoadFlags eFlags, sal_Int32 nScalePercentage)
52  : msName(rName)
53  , msStyle(rStyle)
54  , mrBitmap(rBitmap)
55  , mbLocalized(bLocalized)
56  , meFlags(eFlags)
57  , mbWriteImageToCache(false)
58  , mnScalePercentage(nScalePercentage)
59  {}
60 
61  bool convertToDarkTheme();
62  sal_Int32 scalePercentage();
63 };
64 
66 {
67 public:
68  ImplImageTree();
70 
71  OUString getImageUrl(
72  OUString const & name, OUString const & style, OUString const & lang);
73 
74  std::shared_ptr<SvMemoryStream> getImageStream(
75  OUString const & rName, OUString const & rStyle, OUString const & rLang);
76 
77  bool loadImage(
78  OUString const & name, OUString const & style,
79  BitmapEx & bitmap, bool localized,
80  const ImageLoadFlags eFlags,
81  sal_Int32 nScalePercentage = -1);
82 
86  void shutdown();
87 
88  css::uno::Reference< css::container::XNameAccess > const & getNameAccess();
89 
90 private:
91  ImplImageTree(const ImplImageTree&) = delete;
92  ImplImageTree& operator=(const ImplImageTree&) = delete;
93 
94  typedef std::unordered_map<OUString, std::pair<bool,BitmapEx>> IconCache;
95  typedef std::unordered_map<sal_Int32, std::unique_ptr<IconCache>> ScaledIconCache;
96  typedef std::unordered_map<OUString, OUString> IconLinkHash;
97 
98  struct IconSet
99  {
100  OUString maURL;
101  css::uno::Reference<css::container::XNameAccess> maNameAccess;
102  ScaledIconCache maScaledIconCaches;
103  IconLinkHash maLinkHash;
104 
106  {}
107 
108  IconSet(const OUString & rURL)
109  : maURL(rURL)
110  {}
111  };
112 
115  std::unordered_map<OUString, IconSet> maIconSets;
116 
118  OUString maCurrentStyle;
119 
121  {
122  return maIconSets[maCurrentStyle];
123  }
124 
125  bool doLoadImage(ImageRequestParameters& rParameters);
126 
127  std::vector<OUString> getPaths(OUString const & name, LanguageTag const & rLanguageTag);
128 
129  bool checkPathAccess();
130 
131  void setStyle(OUString const & rStyle);
132 
133  void createStyle();
134 
135  IconCache &getIconCache(const ImageRequestParameters& rParameters);
136 
137  bool iconCacheLookup(ImageRequestParameters& rParameters);
138 
139  bool findImage(std::vector<OUString> const & rPaths, ImageRequestParameters& rParameters);
140 
141  void loadImageLinks();
142 
143  void parseLinkFile(std::shared_ptr<SvStream> const & aStream);
144 
146  OUString const & getRealImageName(OUString const & rName);
147 
148 
153  static OUString fallbackStyle(const OUString &rStyle);
154 };
155 
156 #endif
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool iconCacheLookup(ImageRequestParameters &rParameters)
ImageLoadFlags
Definition: ImageTree.hxx:31
OUString maCurrentStyle
Style used for the current operations; switches switch several times during fallback search...
void shutdown()
a crude form of life cycle control (called from DeInitVCL; otherwise, if the ImplImageTree singleton ...
bool findImage(std::vector< OUString > const &rPaths, ImageRequestParameters &rParameters)
IconSet(const OUString &rURL)
IconCache & getIconCache(const ImageRequestParameters &rParameters)
Find an icon cache for the right scale factor.
ScaledIconCache maScaledIconCaches
css::uno::Reference< css::container::XNameAccess > const & getNameAccess()
OUString const msStyle
std::unordered_map< OUString, std::pair< bool, BitmapEx > > IconCache
css::uno::Reference< css::container::XNameAccess > maNameAccess
static OUString fallbackStyle(const OUString &rStyle)
Return name of the fallback style for the provided one.
IconSet & getCurrentIconSet()
std::unordered_map< OUString, IconSet > maIconSets
Remember all the (used) icon styles and individual icons in them.
bool doLoadImage(ImageRequestParameters &rParameters)
std::unordered_map< sal_Int32, std::unique_ptr< IconCache > > ScaledIconCache
OUString const & getRealImageName(OUString const &rName)
Return name of a real .png according to links.txt.
void setStyle(OUString const &rStyle)
std::vector< OUString > getPaths(OUString const &name, LanguageTag const &rLanguageTag)
std::unordered_map< OUString, OUString > IconLinkHash
OUString getImageUrl(OUString const &name, OUString const &style, OUString const &lang)
bool loadImage(OUString const &name, OUString const &style, BitmapEx &bitmap, bool localized, const ImageLoadFlags eFlags, sal_Int32 nScalePercentage=-1)
bool checkPathAccess()
ImageRequestParameters(const OUString &rName, const OUString &rStyle, BitmapEx &rBitmap, bool bLocalized, ImageLoadFlags eFlags, sal_Int32 nScalePercentage)
void parseLinkFile(std::shared_ptr< SvStream > const &aStream)
ImplImageTree & operator=(const ImplImageTree &)=delete
std::shared_ptr< SvMemoryStream > getImageStream(OUString const &rName, OUString const &rStyle, OUString const &rLang)
const char * name
ImageLoadFlags const meFlags